コード例 #1
0
        //POST : /api/ApplicationUser/Register
        public async Task <IActionResult> ResetPassword(ResetPass model)
        {
            try
            {
                var user = await _userManager.FindByNameAsync(model.UserName);

                if (user == null)
                {
                    return(BadRequest(new { message = "Username is incorrect." }));
                }
                var tokenDescriptor = new SecurityTokenDescriptor
                {
                    Subject = new ClaimsIdentity(new Claim[]
                    {
                        new Claim("UserID", user.Id.ToString())
                    }),
                    Expires            = DateTime.UtcNow.AddDays(1),
                    SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appSettings.JWT_Secret)), SecurityAlgorithms.HmacSha256Signature)
                };
                var tokenHandler  = new JwtSecurityTokenHandler();
                var securityToken = tokenHandler.CreateToken(tokenDescriptor);
                var token         = tokenHandler.WriteToken(securityToken);

                var result = await _userManager.ResetPasswordAsync(user, token, model.password2);


                return(Ok(result));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public ActionResult ThongTinCaNhan(ResetPass resetPass)
        {
            if (resetPass != null && resetPass.MatKhauCu != null && resetPass.MatKhauCu.Length > 0 && resetPass.MatKhauMoi.Length > 0 && resetPass.ReMatKhauMoi.Length > 0)
            {
                tongcuclamnghiepEntities tongcuclamnghiep = new tongcuclamnghiepEntities();
                AccountCookie            accountCookie    = (AccountCookie)Session["AccountCookie"];
                ResSubmit resSubmit = new ResSubmit(true, "Cập nhật thành công");
                var       _Account  = tongcuclamnghiep.m_account.Where(a => a.id == accountCookie.Id && a.password == resetPass.MatKhauCu).FirstOrDefault();
                if (_Account == null)
                {
                    resSubmit = new ResSubmit(false, "Không có tài khoản này");
                }
                if (resSubmit.success && !(resetPass.MatKhauMoi == resetPass.ReMatKhauMoi && (resetPass.MatKhauMoi.Length >= 12 && resetPass.MatKhauMoi.Length <= 50)))
                {
                    resSubmit = new ResSubmit(false, "Mật khẩu mới không hợp lệ");
                }
                if (resSubmit.success)
                {
                    _Account.password = resetPass.MatKhauMoi;
                    if (tongcuclamnghiep.SaveChanges() != 1)
                    {
                        resSubmit = new ResSubmit(false, "Cập nhật thất bại");
                    }
                    else
                    {
                        string body = string.Format(@"<table width='100%' cellspacing='0' cellpadding='0' border='0' style='width:100%;min-width:100%'>
			<tbody>
            <tr>
				<td align='left' style='padding:0;font-size:20px;line-height:26px;letter-spacing:-0.32px;font-weight:normal;font-family:'Segoe UI Semibold','Segoe UI',SUWSB,Arial,sans-serif;color:#0078d6'>
					Tóm tắt tài khoản
				</td>
			</tr>
			<tr>
				<td class='m_-8498465890789338487useremail' align='left' style='padding:3px 0 0;font-size:14px;line-height:19px;letter-spacing:-0.16px;font-weight:normal;font-family:'Segoe UI','Segoe UI Regular',SUWR,Arial,sans-serif;color:#6e6e6e'>
					<b style='font-family:'Segoe UI Semibold','Segoe UI',SUWSB,Arial,sans-serif;font-weight:normal'>Tên Tài khoản:</b> <a href='#m_-8498465890789338487_' style='text-decoration:none;color:#737373'>{0}</a>
				</td>
			</tr>
            <tr>
				<td class='m_-8498465890789338487useremail' align='left' style='padding:3px 0 0;font-size:14px;line-height:19px;letter-spacing:-0.16px;font-weight:normal;font-family:'Segoe UI','Segoe UI Regular',SUWR,Arial,sans-serif;color:#6e6e6e'>
					<b style='font-family:'Segoe UI Semibold','Segoe UI',SUWSB,Arial,sans-serif;font-weight:normal'>Mật khẩu:</b> <a href='#m_-8498465890789338487_' style='text-decoration:none;color:#737373'>{1}</a>
				</td>
			</tr>
			<tr>
				<td align='left' style='padding:3px 0 0;font-size:14px;line-height:19px;letter-spacing:-0.16px;font-weight:normal;font-family:'Segoe UI Semibold','Segoe UI',SUWSB,Arial,sans-serif;color:#6e6e6e'>
					<a href='http://baocaolamnghiep.quantriwebhanoi.com' style='color:#6e6e6e;text-decoration:underline' target='_blank' ><strong style='font-weight:normal'>Tài khoản của Tôi</strong></a>
				</td>
			</tr>
		</tbody></table>"        , _Account.username, _Account.password);
                        FuncExtend.SendMail(_Account.email, body, "Thông tin tài khoản");
                    }
                }
                ModelState.AddModelError("", resSubmit.message);
                return(View());
            }
            else
            {
                return(View());
            }
        }
コード例 #3
0
        private void ResetPasse_Click(object sender, RoutedEventArgs e)
        {
            var wind = new ResetPass(_PSEUDO.Text.Trim())
            {
                Owner = Window.GetWindow(this)
            };

            wind.ShowDialog();
        }
コード例 #4
0
ファイル: FrmLogin.cs プロジェクト: Arsiii/Store1
        private void Resetbutton_Click(object sender, EventArgs e)
        {
            ResetPass abc = new ResetPass();

            abc.Show();
        }