public async Task <IActionResult> Create(UserRequestModel UserRequest) { try { string Salt = SecureUtility.GetSalt(); string ModifiedSalt = UserRequest.Password + Salt; string HashPassword = SecureUtility.GetHash(ModifiedSalt); UserRequest.PasswordHash = HashPassword; UserRequest.Salt = Salt; var UserDtos = _mapper.Map <Users>(UserRequest); bool result = await _userService.CreateUser(UserDtos); if (result) { //return Ok(); return(Ok(new { status = HttpStatusCode.OK, valid = true, msg = "You have been successfully registered" })); } return(Ok(new { status = HttpStatusCode.InternalServerError, valid = true, msg = "Something went wrong" })); } catch (Exception ex) { return(Ok(new { status = HttpStatusCode.InternalServerError, valid = true, msg = ex.InnerException.Message })); } // return new HttpResponseMessage(HttpStatusCode.InternalServerError); }
/// <summary>Updates a user to the Horeb data source.</summary> /// <param name="user">The user (HorebUser) to update.</param> /// <exception cref="T:System.ArgumentNullException"> public void UpdateUser(HorebUser user) { if (user == null || user == HorebUser.Empty) { throw new ArgumentNullException(nameof(user)); } string email = user.Email; SecureUtility.CheckParameter(ref email, true, true, true, 256, nameof(email)); user.Email = email; _userDao.Update(user); }
/// <summary>Logs in a the given Horeb user and updates the last-activity date/time stamp if sucessful.</summary> /// <param name="username">The user name to log-in.</param> /// <param name="logInStatus">The status of the log-in action.</param> /// <returns> True if the user was logged on successfully. False otherwise.</returns> /// <exception cref="T:System.ArgumentNullException"> public bool Login(string username, out LoginStatus logInStatus) { SecureUtility.CheckParameter(ref username, true, false, true, 256, nameof(username)); if (!_userDao.DoesUserExist(username)) { logInStatus = LoginStatus.UserDoesNotExist; return(false); } HorebUser user = _userDao.Find(username); _userDao.UpdateUserActivity(user.Id); _applicationStateSetter.SetCurrentLoggedInUser(username); logInStatus = LoginStatus.LoggedIn; return(true); }
/// <summary>Logs in a the given Horeb user and updates the last-activity date/time stamp if sucessful.</summary> /// <param name="username">The user name (username) to log-in.</param> /// <param name="password">The password to match to the user to log-in</param> /// <param name="logInStatus">The status of the log-in action.</param> /// <returns> True if the user was logged on successfully. False otherwise.</returns> /// <exception cref="T:System.ArgumentNullException"> public bool Login(string username, string password, out LoginStatus logInStatus) { SecureUtility.CheckParameter(ref username, true, false, true, 256, nameof(username)); SecureUtility.CheckPasswordParameter(ref password, 15, nameof(username)); if (_userDao.DoesUserExist(username)) { logInStatus = LoginStatus.UserDoesNotExist; return(false); } HorebUser user = _userDao.Find(username); if (!_userDao.FindUserPassword(user.Id).Equals(password)) { logInStatus = LoginStatus.InvalidPassword; return(false); } return(Login(username, out logInStatus)); }
/// <summary>Creates a user and returns an Horeb user from the Horeb data source.</summary> /// <param name="username">The user name (username) to create.</param> /// <param name="password">The password for the user</param> /// <returns> If successful return the newly created user. Returns an Emtpy user otherwise.</returns> /// <exception cref="T:System.ArgumentNullException"> public HorebUser CreateUser(string username, string password, out CreateUserStatus status) { if (!SecureUtility.ValidateParameter(ref username, true, true, true, 0)) { status = CreateUserStatus.InvalidUserName; return(HorebUser.Empty); } if (!SecureUtility.ValidatePasswordParameter(ref password, 0)) { status = CreateUserStatus.InvalidPassword; return(HorebUser.Empty); } if (_userDao.DoesUserExist(username)) { status = CreateUserStatus.DuplicateUserName; return(HorebUser.Empty); } status = CreateUserStatus.Success; return(_userDao.Insert(username, password)); }
public async Task <Users> Authenticate(string Email, string Password) { using (UnitOfWork db = new UnitOfWork()) { FilterDefinition <Users> filter = Builders <Users> .Filter.Eq("Email", Email); var result = await db.Users.Find(filter); if (result != null) { string Salt = result.Salt; string ModifiedSalt = Password + Salt; string HashPassword = SecureUtility.GetHash(ModifiedSalt); if (HashPassword.Equals(result.PasswordHash)) { return(result); } } } return(null); }
/// <summary>Gets a wallet where the name contains the specified name to match.</summary> /// <param name="nameToMatch">The name to search for.</param> /// <returns>A List of <see cref="T:Horeb.Domain.WalletModule.Wallet" /> that contains the wallets to match the <paramref name="nameToMatch" /> /// parameter.Leading and trailing spaces are trimmed from the <paramref name="nameToMatch" /> parameter value.</returns> public List <Wallet> FindWalletByName(string nameToMatch) { SecureUtility.CheckParameter(ref nameToMatch, true, false, true, 256, nameof(nameToMatch)); return(_walletDao.FindByName(nameToMatch).ToList()); }
/// <summary>Creates a wallet and returns a wallet from the Horeb data source.</summary> /// <param name="walletName">The user name (username) to create.</param> /// <returns> If successful return the newly created wallet. Returns an Emtpy wallet otherwise.</returns> /// <exception cref="T:System.ArgumentNullException"> public Wallet CreateWallet(string walletName) { SecureUtility.CheckParameter(ref walletName, true, true, true, 256, nameof(walletName)); return(_walletDao.Insert(walletName)); }
/// <summary>Gets an Horeb users where the e-mail address contains the specified e-mail address to match.</summary> /// <param name="emailToMatch">The e-mail address to search for.</param> /// <returns>A <see cref="T:Horeb.Domain.UserModule.HorebUser" /> that contains all users that match the <paramref name="emailToMatch" /> /// parameter.Leading and trailing spaces are trimmed from the <paramref name="emailToMatch" /> parameter value.</returns> public HorebUser FindUserByEmail(string emailToMatch) { SecureUtility.CheckParameter(ref emailToMatch, true, false, false, 256, nameof(emailToMatch)); return(_userDao.FindByEmail(emailToMatch)); }
/// <summary>Gets an Horeb users where the user name contains the specified username to match.</summary> /// <param name="userName">The user name to search for.</param> /// <returns>A <see cref="T:Horeb.Domain.UserModule.HorebUser" /> that contains all users that match the <paramref name="userName" /> parameter.</returns> /// <exception cref="T:System.ArgumentException"> /// <paramref name="userName" /> is an empty string.</exception> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="userName" /> is <see langword="null" />.</exception> public HorebUser FindUser(string userName) { SecureUtility.CheckParameter(ref userName, true, true, true, 256, nameof(userName)); return(_userDao.Find(userName)); }