public async Task RealEstateUserCreateAsync(Users usr) { try { using (IUserTransaction tran = await RealEstateDB.OpenWithTransactionAsAsync<IUserTransaction>()) { int userId = await tran.RealEstateUserCreateAsync(usr); if (usr.Roles == null) { //set the default role to NormalUser usr.Roles = new List<AppRole>() { new AppRole { AppRoleId = (int)ApplicationRoles.NormalUser } }; } if (userId > 0 && !usr.Roles.IsNullOrEmpty()) { foreach (var role in usr.Roles) { UserToAppRole u2ar = new UserToAppRole(); u2ar.UserId = usr.UserId; u2ar.AppRoleId = role.AppRoleId; await tran.RealEstateUserToAppRoleCreateAsync(u2ar); } } tran.Commit(); } } catch (Exception ex) { logger.Error(string.Format("Error creating the user with username:{0} and email : {1}", usr.LoginName, usr.EmailAddress), ex); throw new DALException("Couldnot create the user"); } }
public async Task<Users> ValidateUser(Users usr) { try { return await RealEstateDB.SingleAsync<Users>("dbo.UserReadByLoginName", usr); } catch (Exception ex) { logger.Error(string.Format("Error validating the user with username:{0} and email : {1}", usr.LoginName), ex); throw new DALException("Couldnot validate the user"); } }
private static void CreateRealEstateUser() { Users usr = new Users(); usr.LoginName = "nathan8825"; usr.UserPassword = "******"; usr.EmailAddress = "*****@*****.**"; usr.IsActive = true; usr.Phone = "9047894526"; usr.Roles = new List<AppRole> { new AppRole {AppRoleId = 1} }; new UserLogic().RealEstateUserCreateAsync(usr); Console.WriteLine("Successfully added user and Roles"); }
public async Task RealEstateUserCreateAsync(Users usr) { try { new CryptoUtil().SecureUser(usr); await UserDAL.RealEstateUserCreateAsync(usr); } catch (DALException dex) { throw BLLException.CopyDALException(dex); } catch (Exception ex) { logger.Error(string.Format("Error creating the user with username:{0} and email : {1}", usr.LoginName, usr.EmailAddress), ex); throw new BLLException("Error creatiing user"); } }
public async Task<bool> ValidateUser(string userName, string txtPassword) { try { Users userTobeValidated = new Users { LoginName = userName, UserPassword = txtPassword }; new CryptoUtil().SecureUser(userTobeValidated); Users databaseUser = await UserDAL.ValidateUser(new Users { LoginName = userName }); if (databaseUser != null && databaseUser.UserPassword != null && databaseUser.PasswordSalt != null && databaseUser.UserPassword.Equals(userTobeValidated.HashedPassword) && databaseUser.PasswordSalt.Equals(userTobeValidated.PasswordSalt)) { return true; } return false; } catch (Exception) { throw; //logger.Error(string.Format("Error validating the user with username:{0}", userName, ex)); //throw new BLLException("Error validating the user"); } }
public Users SecureUser(Users usr) { usr.PasswordSalt = this.CreateSalt(usr.LoginName); usr.HashedPassword = this.HashPassword(usr.PasswordSalt, usr.UserPassword); return usr; }
private PasswordReset SetupUserForPasswordReset(Users usr) { string baseUrl = ConfigurationManager.AppSettings["RealEstateBaseUrl"].ToString(); string token = Guid.NewGuid().ToString().Replace("-", ""); PasswordReset reset = new PasswordReset(); reset.Url = baseUrl; reset.Token = token; reset.Expires = DateTime.Now.AddHours(3); reset.UserId = usr.UserId; return reset; }
/// <summary> /// Resets the user password when the user clicks the link in the email and provides a new password /// </summary> /// <param name="Token"></param> /// <param name="newPassword"></param> /// <returns></returns> public async Task ResetPassword(string Token, string newPassword) { try { PasswordReset pr = await RealEstateDB.SingleAsync<PasswordReset>("dbo.UserReadByToken", Token); if (pr != null && pr.Expires > DateTime.Now) { Users newUser = new Users { LoginName = pr.LoginName, UserPassword = newPassword }; new CryptoUtil().SecureUser(newUser); await RealEstateDB.ExecuteAsync("dbo.[UserPasswordUpdate]", newUser); } } catch (Exception ex) { logger.Error(string.Format("Error resetting the userpassword with token:{0}", Token, ex)); throw new DALException("Error resetting the userpassword "); } }