/// <inheritdoc /> public async Task <AuthenticationResultDto> RegisterAsync(UserRegistrationRequest request) { var existingUser = await userManager.FindByEmailAsync(request.Email); if (existingUser != null) { var message = "User with this email address already exists"; await securityAuditService.ProcessFailedRegistrationAsync(request, message); return(new AuthenticationResultDto { Errors = new[] { message }, }); } var newUser = new CWUser { Email = request.Email, UserName = request.Email }; var result = await userManager.CreateAsync(newUser, request.Password); if (!result.Succeeded) { await securityAuditService.ProcessFailedRegistrationAsync(request, result); return(new AuthenticationResultDto { Errors = result.Errors.Select(x => x.Description) }); } return(await tokenService.Generate(newUser)); }
private void btnsubmit_Click(object sender, EventArgs e) { try { if (PerformValidation()) { if (txtNewPasswd.Text != txtRePasswd.Text) { AddFunc.MsgError("Password does not match !"); } else { if (txtoldPasswd.Text == txtNewPasswd.Text) { AddFunc.MsgError("New password can not be same old password !"); } else { CWUser.ChangePasswordCWUser(txtUsername.Text, txtNewPasswd.Text, txtoldPasswd.Text); AddFunc.MsgInfo("Change Password Succesfull"); } } } } catch (Exception ex) { AddFunc.MsgError(ex.Message); } }
private RefreshToken GenerateRefreshToken(CWUser user) { return(new RefreshToken { UserId = user.Id, ExpiryDate = DateTime.UtcNow.AddSeconds(jwtSettings.RefreshTokenLifetimeInSeconds), }); }
private void LoadComboBox() { cboEmployee.DataSource = Employee.GetEmployee(); cboEmployee.ValueMember = "Id"; cboEmployee.DisplayMember = "Nama"; cboUserGroup.DataSource = CWUser.GetAllCWUserGroup(); cboUserGroup.ValueMember = "CWUserGroup"; cboUserGroup.DisplayMember = "CWUserGroup"; }
private async Task <string> GetPasswordResetLink(CWUser user) { // generate password token var pwdResetToken = await userManager.GeneratePasswordResetTokenAsync(user); var value = new { email = user.Email, token = pwdResetToken }; return(urlHelper.RouteUrl( Constants.RouteNames.ResetPassword, value, urlHelper.ActionContext.HttpContext.Request.Scheme)); }
/// <inheritdoc /> public async Task <AuthenticationResultDto> Generate(CWUser user) { var(token, refreshToken) = GenerateTokenPair(user); await repository.SaveNewTokenAsync(refreshToken); return(new AuthenticationResultDto { Success = true, Token = tokenHandler.WriteToken(token), RefreshToken = refreshToken.Id, }); }
public FrmUserGroupRoles(MenuStrip _mainform) { InitializeComponent(); listbutton = CWUser._UserGroupRoles.Where(x => x.Parent == this.Text && x.Tag == "button" && x.Permission == true).Select(y => y.elementName).ToList(); ButtonMapperHelper.GetButtons(this, listbutton); formbuttonlist = CWUserGroup.RetrieveAllFormButton(); PopulateToolstripMenuItem(_mainform); listusergroup = CWUserGroup.RetrieveAllUserGroup(); lboUserGroup.DataSource = listusergroup.Select(x => x.Id).ToList(); listusergrouproles = CWUserGroup.RetrieveAllUserGroupRoles(); GetAllForm(); listuser = CWUser.GetAllUser(); lboUser.DataSource = listuser.Where(y => y.UsergroupId == "ADM").Select(x => x.UserId).ToList(); }
private SecurityTokenDescriptor GenerateTokenDescriptor(CWUser user) { var key = Encoding.ASCII.GetBytes(jwtSettings.Secret); var now = DateTime.UtcNow; var sumKey = new SymmetricSecurityKey(key); return(new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim(JwtRegisteredClaimNames.Sub, user.Id), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), new Claim(JwtRegisteredClaimNames.Email, user.Email), }), Expires = now.AddSeconds(jwtSettings.TokenLifetimeInSeconds), SigningCredentials = new SigningCredentials( sumKey, SecurityAlgorithms.HmacSha256Signature), }); }
private void btnLogin_Click(object sender, EventArgs e) { if (PerformValidation()) { CWUser.ValidateUser(txtUsername.Text, txtPassword.Text); if (CWUser._UserInfo == null) { MessageBox.Show("Please check your user id and password", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); txtPassword.Text = txtUsername.Text = string.Empty; txtUsername.Focus(); } else { this.DialogResult = DialogResult.OK; } } else { } }
private MailMessage GetEmailMessage(CWUser user, string pwdResetLink) { var emailSettings = new EmailSettings(); configuration.Bind(nameof(EmailSettings), emailSettings); var messageBody = $"Click here to reset your password: <a href=\"{pwdResetLink}\">link</a>"; var msg = new MailMessage { From = new MailAddress(emailSettings.FromEmail), Subject = "Password reset", IsBodyHtml = true, Body = messageBody, }; msg.To.Add(new MailAddress(user.Email)); return(msg); }
private void btnAdd_Click(object sender, EventArgs e) { try { if (PerfomValidation()) { if (_form == FormMode.New) { CopyGUI2BL(); CWUser.AddCWUser(obj); AddFunc.MsgInfo("Add User Succesfull"); } else if (_form == FormMode.Update) { } _form = FormMode.View; SetupFormMode(); } }catch (Exception ex) { AddFunc.MsgError(ex.Message); } }
private SecurityToken GenerateToken(CWUser user) { var tokenDescriptor = GenerateTokenDescriptor(user); return(tokenHandler.CreateToken(tokenDescriptor)); }
private (SecurityToken Token, RefreshToken RefreshToken) GenerateTokenPair(CWUser user) { return(GenerateToken(user), GenerateRefreshToken(user)); }
/// <inheritdoc /> public async Task <bool> IsAlreadyLogged(CWUser user) { return(await repository.IsAlreadyLogged(user.Id)); }
private void btnSearch_Click(object sender, EventArgs e) { dgResult.DataSource = CWUser.GetAllUser(); }