Profile avatar

This commit is contained in:
DawitG96
2019-01-18 23:24:50 +01:00
parent 1246116804
commit 4294f48fd8
8 changed files with 113 additions and 21 deletions

View File

@@ -6,6 +6,8 @@ using LinqToDB;
using System.Linq;
using System;
using SeniorAssistant.Models.Users;
using System.Web;
using System.IO;
namespace IdentityDemo.Controllers
{
@@ -61,13 +63,20 @@ namespace IdentityDemo.Controllers
}
[HttpPost]
public ActionResult _register(User user)
public ActionResult _register(User user, string code = "")
{
return Action(() =>
{
try
{
Db.Insert(user);
if(code != null && code.Equals("444442220"))
{
Db.Insert(new Doctor
{
Username = user.Username
});
};
return _login(user.Username, user.Password);
}
catch
@@ -181,5 +190,49 @@ namespace IdentityDemo.Controllers
return Json(OkJson);
});
}
[HttpPost]
public async System.Threading.Tasks.Task<ActionResult> Save(IFormFile file)
{
return LoggedAction(() =>
{
var loggedUser = HttpContext.Session.GetString(Username);
if (file.Length > 0)
{
var name = loggedUser + ".jpg";
var path = Path.Combine(("~/uploads/"), name);
var stream = new FileStream(path, FileMode.Create);
file.CopyTo(stream);
var user = (from u in Db.Users
where u.Username.Equals(loggedUser)
select u).FirstOrDefault();
user.Avatar = path;
Db.Update(User);
}
return Json(OkJson);
});
/*
var loggedUser = HttpContext.Session.GetString(Username);
long size = file.Length;
// full path to file in temp location
var filePathPart = Path.GetDirectoryName("~/AdminLTE-2.4.3/dist/img/");
var fileName = Path.GetFileName(loggedUser + ".jpg");
var filePath = Path.Combine(filePathPart,fileName);
if (size > 0)
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
await file.CopyToAsync(stream);
}
}
return Json(new JsonResponse());
*/
}
}
}

View File

@@ -18,5 +18,7 @@ namespace SeniorAssistant.Models
public string Name { get; set; }
public string LastName { get; set; }
public string Avatar { get; set; }
}
}

View File

@@ -7,7 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
<Folder Include="wwwroot\uploads\" />
</ItemGroup>
<ItemGroup>

View File

@@ -14,7 +14,19 @@
<ul class="dropdown-menu">
<!-- The user image in the menu -->
<li class="user-header">
<img src="~/AdminLTE-2.4.3/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
<img src="@session.GetString("avatar")" class="img-circle" alt="User Image" id="avatar">
<div>
<input type="button" class="btn-flat" value="+" id="btn-plus" />
</div>
<!--<div id="image-uploader" style="display:none">
<input name="files" id="files" type="file" />
</div>-->
<div id="image-uploader" style="display:none">
<form method="post" enctype="multipart/form-data">
<input type="file" name="files" id="files" />
</form>
</div>
<p>
@session.GetString("name") @session.GetString("lastname") - @session.GetString("role")
<small>@session.GetString("email")</small>
@@ -32,6 +44,19 @@
</ul>
<script>
$(document).ready(function () {
$("#files").kendoUpload({
async: {
saveUrl: "save",
autoUpload: true
}
});
});
$("#btn-plus").on("click", function () {
$("#image-uploader").toggle();
});
$("#logout-btn").on("click", function () {
$.ajax({
url: "/Account/_logout",

View File

@@ -78,7 +78,7 @@
where p.Doctor.Equals(docData.Username)
select new { u.Username, u.Name, u.LastName, p.Notes, Profile = "<a href=\\\"/user/" + u.Username + "\\\">Profile</a>" }).ToArray();
data = patients;
type = patients.FirstOrDefault().GetType();
type = patients.FirstOrDefault()?.GetType();
}
else // is a patient and need to choose a doctor
{
@@ -91,15 +91,19 @@
type = docs.FirstOrDefault().GetType();
}
var fields = new List<string>();
foreach (var field in type.GetProperties())
if (type != null)
{
fields.Add(field.Name);
}
<p>@title</p>
<div id="var-table"></div>
<script>
var fields = new List<string>();
foreach (var field in type.GetProperties())
{
fields.Add(field.Name);
}
<p>@title</p>
<div id="var-table"></div>
<script>
var datas = [
@foreach (var el in data)
{
@@ -156,7 +160,8 @@
</text>
}
});
</script>
</script>
}
}
</div>
</div>

View File

@@ -5,7 +5,7 @@
<input type="text" id="regLastname" placeholder="Lastname" />
<input type="password" id="regPassword" placeholder="Password" required />
<input type="email" id="regEmail" placeholder="Email" required />
<label>Doc?</label><input type="checkbox" id="regDoctor" />
<input type="text" id="regDoctor" placeholder="Doctor only (543210)" />
<div>
<button class="btn-default btn btn-flat" id="register-btn">Register</button>
</div>
@@ -20,17 +20,19 @@
var lastname = $("#regLastname").val();
var password = $("#regPassword").val();
var email = $("#regEmail").val();
var role = $("#regDoctor").is(":checked")? "Doctor":"User";
var code = $("#regDoctor").val();
$.ajax({
url: "/Account/_register",
data: {
Username: username,
Name: name,
Lastname: lastname,
Password: password,
Email: email,
Role: role
Code: code,
User: {
Username: username,
Name: name,
Lastname: lastname,
Password: password,
Email: email
}
},
dataType: "json",
type: "POST",
@@ -43,7 +45,7 @@
}
},
error: function (xhr, status, error) {
alert(xhr.responseText)
alert(error)
}
})
});

View File

@@ -0,0 +1,5 @@
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": []
}

BIN
SeniorAssistant/senior.db Normal file

Binary file not shown.