Skip to content

Commit

Permalink
User Profile
Browse files Browse the repository at this point in the history
  • Loading branch information
XuanThuLab committed Sep 14, 2020
1 parent 87cec00 commit 9745c78
Show file tree
Hide file tree
Showing 31 changed files with 593 additions and 134 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,25 @@ public async Task<IActionResult> OnGetAsync(string userId, string email, string
var user = await _userManager.FindByIdAsync(userId);
if (user == null)
{
return NotFound($"Unable to load user with ID '{userId}'.");
return NotFound($"Không nạp được ID '{userId}'.");
}

code = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
var result = await _userManager.ChangeEmailAsync(user, email, code);
if (!result.Succeeded)
{
StatusMessage = "Error changing email.";
StatusMessage = "Lỗi đổi email.";
foreach (var item in result.Errors)
{
StatusMessage += item.Description;
}


return Page();
}

/*
// In our UI email and user name are one and the same, so when we update the email
// we need to update the user name.
var setUserNameResult = await _userManager.SetUserNameAsync(user, email);
Expand All @@ -56,9 +64,10 @@ public async Task<IActionResult> OnGetAsync(string userId, string email, string
StatusMessage = "Error changing user name.";
return Page();
}
*/

await _signInManager.RefreshSignInAsync(user);
StatusMessage = "Thank you for confirming your email change.";
StatusMessage = "Email đã thay đổi.";
return Page();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ public async Task<IActionResult> OnPostAsync (string returnUrl = null) {
return Page ();
}
}

return Page ();

}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page
@model ChangePasswordModel
@{
ViewData["Title"] = "Change password";
ViewData["Title"] = "Đổi mật khẩu";
ViewData["ActivePage"] = ManageNavPages.ChangePassword;
}

Expand All @@ -26,7 +26,7 @@
<input asp-for="Input.ConfirmPassword" class="form-control" />
<span asp-validation-for="Input.ConfirmPassword" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Update password</button>
<button type="submit" class="btn btn-primary">Cập nhật mật khẩu</button>
</form>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ public class InputModel
{
[Required]
[DataType(DataType.Password)]
[Display(Name = "Current password")]
[Display(Name = "Password hiện tại")]
public string OldPassword { get; set; }

[Required]
[StringLength(100, ErrorMessage = "The {0} must be at least {2} and at max {1} characters long.", MinimumLength = 6)]
[StringLength(100, ErrorMessage = "{0} dài {2} đến {1} ký tự.", MinimumLength = 6)]
[DataType(DataType.Password)]
[Display(Name = "New password")]
[Display(Name = "Password mới")]
public string NewPassword { get; set; }

[DataType(DataType.Password)]
[Display(Name = "Confirm new password")]
[Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
[Display(Name = "Nhập lại password mới")]
[Compare("NewPassword", ErrorMessage = "Password phải giống nhau.")]
public string ConfirmPassword { get; set; }
}

Expand All @@ -56,7 +56,7 @@ public async Task<IActionResult> OnGetAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
return NotFound($"Lỗi nạp User với ID '{_userManager.GetUserId(User)}'.");
}

var hasPassword = await _userManager.HasPasswordAsync(user);
Expand All @@ -78,7 +78,7 @@ public async Task<IActionResult> OnPostAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
return NotFound($"Lỗi nạp User với ID '{_userManager.GetUserId(User)}'.");
}

var changePasswordResult = await _userManager.ChangePasswordAsync(user, Input.OldPassword, Input.NewPassword);
Expand All @@ -93,7 +93,7 @@ public async Task<IActionResult> OnPostAsync()

await _signInManager.RefreshSignInAsync(user);
_logger.LogInformation("User changed their password successfully.");
StatusMessage = "Your password has been changed.";
StatusMessage = "Đã thay đổi password thành công.";

return RedirectToPage();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@page
@model EmailModel
@{
ViewData["Title"] = "Manage Email";
ViewData["Title"] = "QUẢN LÝ EMAIL";
ViewData["ActivePage"] = ManageNavPages.Email;
}

Expand Down Expand Up @@ -33,7 +33,7 @@
<input asp-for="Input.NewEmail" class="form-control" />
<span asp-validation-for="Input.NewEmail" class="text-danger"></span>
</div>
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="btn btn-primary">Change email</button>
<button id="change-email-button" type="submit" asp-page-handler="ChangeEmail" class="btn btn-primary">Đổi Email</button>
</form>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class InputModel
{
[Required]
[EmailAddress]
[Display(Name = "New email")]
[Display(Name = "Đổi sang email mới")]
public string NewEmail { get; set; }
}

Expand All @@ -68,7 +68,7 @@ public async Task<IActionResult> OnGetAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
return NotFound($"Khôg nạp được tài khoản ID '{_userManager.GetUserId(User)}'.");
}

await LoadAsync(user);
Expand All @@ -80,7 +80,7 @@ public async Task<IActionResult> OnPostChangeEmailAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
return NotFound($"Khôg nạp được tài khoản ID '{_userManager.GetUserId(User)}'.");
}

if (!ModelState.IsValid)
Expand All @@ -94,21 +94,22 @@ public async Task<IActionResult> OnPostChangeEmailAsync()
{
var userId = await _userManager.GetUserIdAsync(user);
var code = await _userManager.GenerateChangeEmailTokenAsync(user, Input.NewEmail);
code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes (code));
var callbackUrl = Url.Page(
"/Account/ConfirmEmailChange",
pageHandler: null,
values: new { userId = userId, email = Input.NewEmail, code = code },
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(
Input.NewEmail,
"Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
"Xác nhận",
$"Hãy xác nhận Email của bạn bằng cách <a href='{callbackUrl}'>bấm vào đây</a>.");

StatusMessage = "Confirmation link to change email sent. Please check your email.";
StatusMessage = "Hãy mở email để xác nhận thay đổi";
return RedirectToPage();
}

StatusMessage = "Your email is unchanged.";
StatusMessage = "Bạn đã thay đổi email.";
return RedirectToPage();
}

Expand All @@ -117,7 +118,7 @@ public async Task<IActionResult> OnPostSendVerificationEmailAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
return NotFound($"Khôg nạp được tài khoản ID '{_userManager.GetUserId(User)}'.");
}

if (!ModelState.IsValid)
Expand All @@ -137,11 +138,11 @@ public async Task<IActionResult> OnPostSendVerificationEmailAsync()
protocol: Request.Scheme);
await _emailSender.SendEmailAsync(
email,
"Confirm your email",
$"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");
"Xác nhận Email",
$"Xác nhận email <a href='{callbackUrl}'>bấm vào đây</a>.");

StatusMessage = "Verification email sent. Please check your email.";
return RedirectToPage();
StatusMessage = "Hãy mở email để xác nhận";
return RedirectToPage();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
@page
@model ExternalLoginsModel
@{
ViewData["Title"] = "Manage your external logins";
ViewData["Title"] = "Quản lý đăng nhập từ dịch vụ ngoài";
ViewData["ActivePage"] = ManageNavPages.ExternalLogins;
}

<partial name="_StatusMessage" for="StatusMessage" />
@if (Model.CurrentLogins?.Count > 0)
{
<h4>Registered Logins</h4>
<h4>Dch vụ đã đăng ký</h4>
<table class="table">
<tbody>
@foreach (var login in Model.CurrentLogins)
Expand All @@ -22,7 +22,7 @@
<div>
<input asp-for="@login.LoginProvider" name="LoginProvider" type="hidden" />
<input asp-for="@login.ProviderKey" name="ProviderKey" type="hidden" />
<button type="submit" class="btn btn-primary" title="Remove this @login.ProviderDisplayName login from your account">Remove</button>
<button type="submit" class="btn btn-danger btn-sm" title="Remove this @login.ProviderDisplayName login from your account">Xóa</button>
</div>
</form>
}
Expand All @@ -38,14 +38,14 @@
}
@if (Model.OtherLogins?.Count > 0)
{
<h4>Add another service to log in.</h4>
<h4>Thêm liên kết vi dch vngoài.</h4>
<hr />
<form id="link-login-form" asp-page-handler="LinkLogin" method="post" class="form-horizontal">
<div id="socialLoginList">
<p>
@foreach (var provider in Model.OtherLogins)
{
<button id="@($"link-login-button-{provider.Name}")" type="submit" class="btn btn-primary" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">@provider.DisplayName</button>
<button id="@($"link-login-button-{provider.Name}")" type="submit" class="btn btn-success" name="provider" value="@provider.Name" title="Log in using your @provider.DisplayName account">Thêm @provider.DisplayName</button>
}
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task<IActionResult> OnGetAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID 'user.Id'.");
return NotFound($"Không nạp được User 'user.Id'.");
}

CurrentLogins = await _userManager.GetLoginsAsync(user);
Expand All @@ -53,18 +53,18 @@ public async Task<IActionResult> OnPostRemoveLoginAsync(string loginProvider, st
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID 'user.Id'.");
return NotFound($"Không nạp được User 'user.Id'.");
}

var result = await _userManager.RemoveLoginAsync(user, loginProvider, providerKey);
if (!result.Succeeded)
{
StatusMessage = "The external login was not removed.";
StatusMessage = "Không xóa được.";
return RedirectToPage();
}

await _signInManager.RefreshSignInAsync(user);
StatusMessage = "The external login was removed.";
StatusMessage = "Đã hủy liên kết.";
return RedirectToPage();
}

Expand All @@ -84,26 +84,26 @@ public async Task<IActionResult> OnGetLinkLoginCallbackAsync()
var user = await _userManager.GetUserAsync(User);
if (user == null)
{
return NotFound($"Unable to load user with ID 'user.Id'.");
return NotFound($"Không nạp được User 'user.Id'.");
}

var info = await _signInManager.GetExternalLoginInfoAsync(user.Id);
if (info == null)
{
throw new InvalidOperationException($"Unexpected error occurred loading external login info for user with ID '{user.Id}'.");
throw new InvalidOperationException($"Lỗi ID '{user.Id}'.");
}

var result = await _userManager.AddLoginAsync(user, info);
if (!result.Succeeded)
{
StatusMessage = "The external login was not added. External logins can only be associated with one account.";
StatusMessage = "Lỗi - dịch vụ đã liên kết với tài khoản khác";
return RedirectToPage();
}

// Clear the existing external cookie to ensure a clean login process
await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme);

StatusMessage = "The external login was added.";
StatusMessage = "Đã liên kết";
return RedirectToPage();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Profile";
ViewData["Title"] = "HỒ SƠ";
ViewData["ActivePage"] = ManageNavPages.Index;

}

<h4>@ViewData["Title"]@Layout</h4>
<h4>@ViewData["Title"]</h4>
<partial name="_StatusMessage" model="Model.StatusMessage" />
<div class="row">
<div class="col-md-6">
Expand All @@ -21,7 +20,24 @@
<input asp-for="Input.PhoneNumber" class="form-control" />
<span asp-validation-for="Input.PhoneNumber" class="text-danger"></span>
</div>
<button id="update-profile-button" type="submit" class="btn btn-primary">Save</button>
<div class="form-group">
<label asp-for="Input.FullName"></label>
<input asp-for="Input.FullName" class="form-control" />
<span asp-validation-for="Input.FullName" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Address"></label>
<input asp-for="Input.Address" class="form-control" />
<span asp-validation-for="Input.Address" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Input.Birthday"></label>
@Html.TextBoxFor(m => m.Input.Birthday, "{0:dd/MM/yyyy}", new {@class = "form-control"})
@* <input asp-for="Input.Birthday" class="form-control" /> *@
<span asp-validation-for="Input.Birthday" class="text-danger"></span>
</div>

<button id="update-profile-button" type="submit" class="btn btn-danger">Lưu hồ sơ</button>
</form>
</div>
</div>
Expand Down
Loading

0 comments on commit 9745c78

Please sign in to comment.