Profile avatar
This commit is contained in:
@@ -6,6 +6,8 @@ using LinqToDB;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using SeniorAssistant.Models.Users;
|
using SeniorAssistant.Models.Users;
|
||||||
|
using System.Web;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace IdentityDemo.Controllers
|
namespace IdentityDemo.Controllers
|
||||||
{
|
{
|
||||||
@@ -61,13 +63,20 @@ namespace IdentityDemo.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult _register(User user)
|
public ActionResult _register(User user, string code = "")
|
||||||
{
|
{
|
||||||
return Action(() =>
|
return Action(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Db.Insert(user);
|
Db.Insert(user);
|
||||||
|
if(code != null && code.Equals("444442220"))
|
||||||
|
{
|
||||||
|
Db.Insert(new Doctor
|
||||||
|
{
|
||||||
|
Username = user.Username
|
||||||
|
});
|
||||||
|
};
|
||||||
return _login(user.Username, user.Password);
|
return _login(user.Username, user.Password);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
@@ -181,5 +190,49 @@ namespace IdentityDemo.Controllers
|
|||||||
return Json(OkJson);
|
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());
|
||||||
|
*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,5 +18,7 @@ namespace SeniorAssistant.Models
|
|||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string LastName { get; set; }
|
public string LastName { get; set; }
|
||||||
|
|
||||||
|
public string Avatar { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="wwwroot\" />
|
<Folder Include="wwwroot\uploads\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -14,7 +14,19 @@
|
|||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<!-- The user image in the menu -->
|
<!-- The user image in the menu -->
|
||||||
<li class="user-header">
|
<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>
|
<p>
|
||||||
@session.GetString("name") @session.GetString("lastname") - @session.GetString("role")
|
@session.GetString("name") @session.GetString("lastname") - @session.GetString("role")
|
||||||
<small>@session.GetString("email")</small>
|
<small>@session.GetString("email")</small>
|
||||||
@@ -32,6 +44,19 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$("#files").kendoUpload({
|
||||||
|
async: {
|
||||||
|
saveUrl: "save",
|
||||||
|
autoUpload: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#btn-plus").on("click", function () {
|
||||||
|
$("#image-uploader").toggle();
|
||||||
|
});
|
||||||
|
|
||||||
$("#logout-btn").on("click", function () {
|
$("#logout-btn").on("click", function () {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/Account/_logout",
|
url: "/Account/_logout",
|
||||||
|
|||||||
@@ -78,7 +78,7 @@
|
|||||||
where p.Doctor.Equals(docData.Username)
|
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();
|
select new { u.Username, u.Name, u.LastName, p.Notes, Profile = "<a href=\\\"/user/" + u.Username + "\\\">Profile</a>" }).ToArray();
|
||||||
data = patients;
|
data = patients;
|
||||||
type = patients.FirstOrDefault().GetType();
|
type = patients.FirstOrDefault()?.GetType();
|
||||||
}
|
}
|
||||||
else // is a patient and need to choose a doctor
|
else // is a patient and need to choose a doctor
|
||||||
{
|
{
|
||||||
@@ -91,15 +91,19 @@
|
|||||||
type = docs.FirstOrDefault().GetType();
|
type = docs.FirstOrDefault().GetType();
|
||||||
}
|
}
|
||||||
|
|
||||||
var fields = new List<string>();
|
if (type != null)
|
||||||
foreach (var field in type.GetProperties())
|
|
||||||
{
|
{
|
||||||
fields.Add(field.Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
<p>@title</p>
|
var fields = new List<string>();
|
||||||
<div id="var-table"></div>
|
|
||||||
<script>
|
foreach (var field in type.GetProperties())
|
||||||
|
{
|
||||||
|
fields.Add(field.Name);
|
||||||
|
}
|
||||||
|
|
||||||
|
<p>@title</p>
|
||||||
|
<div id="var-table"></div>
|
||||||
|
<script>
|
||||||
var datas = [
|
var datas = [
|
||||||
@foreach (var el in data)
|
@foreach (var el in data)
|
||||||
{
|
{
|
||||||
@@ -156,7 +160,8 @@
|
|||||||
</text>
|
</text>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<input type="text" id="regLastname" placeholder="Lastname" />
|
<input type="text" id="regLastname" placeholder="Lastname" />
|
||||||
<input type="password" id="regPassword" placeholder="Password" required />
|
<input type="password" id="regPassword" placeholder="Password" required />
|
||||||
<input type="email" id="regEmail" placeholder="Email" 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>
|
<div>
|
||||||
<button class="btn-default btn btn-flat" id="register-btn">Register</button>
|
<button class="btn-default btn btn-flat" id="register-btn">Register</button>
|
||||||
</div>
|
</div>
|
||||||
@@ -20,17 +20,19 @@
|
|||||||
var lastname = $("#regLastname").val();
|
var lastname = $("#regLastname").val();
|
||||||
var password = $("#regPassword").val();
|
var password = $("#regPassword").val();
|
||||||
var email = $("#regEmail").val();
|
var email = $("#regEmail").val();
|
||||||
var role = $("#regDoctor").is(":checked")? "Doctor":"User";
|
var code = $("#regDoctor").val();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "/Account/_register",
|
url: "/Account/_register",
|
||||||
data: {
|
data: {
|
||||||
Username: username,
|
Code: code,
|
||||||
Name: name,
|
User: {
|
||||||
Lastname: lastname,
|
Username: username,
|
||||||
Password: password,
|
Name: name,
|
||||||
Email: email,
|
Lastname: lastname,
|
||||||
Role: role
|
Password: password,
|
||||||
|
Email: email
|
||||||
|
}
|
||||||
},
|
},
|
||||||
dataType: "json",
|
dataType: "json",
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@@ -43,7 +45,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
error: function (xhr, status, error) {
|
error: function (xhr, status, error) {
|
||||||
alert(xhr.responseText)
|
alert(error)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
5
SeniorAssistant/libman.json
Normal file
5
SeniorAssistant/libman.json
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"version": "1.0",
|
||||||
|
"defaultProvider": "cdnjs",
|
||||||
|
"libraries": []
|
||||||
|
}
|
||||||
BIN
SeniorAssistant/senior.db
Normal file
BIN
SeniorAssistant/senior.db
Normal file
Binary file not shown.
Reference in New Issue
Block a user