public async Task <IActionResult> ChangePasswordWithToken([FromBody] TokenPasswordDTO token) { if (token == null) { return(NotFound()); } SecurityLinkToken _token = contextUsers.SecurityLinkTokens.Find(token.Token); if (_token == null) { return(NotFound()); } User user = contextUsers.Users.Find(_token.Email); if (user == null || !user.IsActive) { return(NotFound()); } user.Password = token.Password; contextUsers.SecurityLinkTokens.Remove(_token); await contextUsers.SaveChangesAsync(); return(Ok()); }
public IActionResult CheckToken([FromBody] TokenDTO token) { if (token == null) { return(NotFound()); } SecurityLinkToken _token = contextUsers.SecurityLinkTokens.Find(token.token); if (_token == null) { return(NotFound()); } return(Ok()); }
public IActionResult ResetPassword([FromBody] EmailDTO email) { if (email == null) { return(NotFound()); } var user = contextUsers.Users.Find(email.Email); if (user == null || !user.IsActive) { return(NotFound()); } Guid token = Guid.NewGuid(); try { EmailManager.SendResetPasswordLinkEmail(email.Email, user.Name, token.ToString()); } catch (Exception ex) { throw ex; } SecurityLinkToken securityLinkToken = new SecurityLinkToken(); securityLinkToken.Email = email.Email; securityLinkToken.Token = token.ToString(); securityLinkToken.Type = "resetpassword"; securityLinkToken.IsDone = false; contextUsers.SecurityLinkTokens.Add(securityLinkToken); contextUsers.SaveChanges(); return(Ok()); }
public async Task <IActionResult> CheckActivationToken([FromBody] TokenDTO token) { if (token == null) { return(NotFound()); } SecurityLinkToken _token = contextUsers.SecurityLinkTokens.Find(token.token); if (_token == null) { return(NotFound()); } User user = contextUsers.Users.Find(_token.Email); user.IsActive = true; contextUsers.SecurityLinkTokens.Remove(_token); await contextUsers.SaveChangesAsync(); return(Ok()); }
public IActionResult RegisterUser([FromBody] RegisterUserDTO registerInfo) { if (registerInfo == null) { return(NotFound()); } User user = contextUsers.Users.Find(registerInfo.Email); if (user != null && user.IsActive) { return(BadRequest("AlreadyExists")); } if (user == null) { user = new User(); user.UserID = registerInfo.Email; user.Name = registerInfo.Name; user.Password = registerInfo.Password; user.IsActive = false; user.IsFirstLogon = true; user.Role = "user"; user.CreationDateTime = DateTime.Now; contextUsers.Users.Add(user); } else { user.Name = registerInfo.Name; user.Password = registerInfo.Password; user.IsActive = false; user.IsFirstLogon = true; user.Role = "user"; user.CreationDateTime = DateTime.Now; } Guid token = Guid.NewGuid(); try { EmailManager.SendActivationlinkEmail(registerInfo.Email, user.Name, token.ToString()); EmailManager.SendSignUpNotificationEmail(EmailManager.AdminEmail, user.Name, user.UserID); } catch (Exception ex) { throw ex; } SecurityLinkToken securityLinkToken = new SecurityLinkToken(); securityLinkToken.Email = registerInfo.Email; securityLinkToken.Token = token.ToString(); securityLinkToken.Type = "activation"; securityLinkToken.IsDone = false; securityLinkToken.CreationDateTime = DateTime.Now; contextUsers.SecurityLinkTokens.Add(securityLinkToken); contextUsers.SaveChanges(); return(Ok()); }