/// <summary> /// Sends a reset password email to a user /// </summary> /// <param name="username"></param> /// <returns></returns> public bool ForgotPassword(string username) { bool retVal = false; var user = _repositories.Users.GetUserByUsername(username); if (user != null) { Passwordrequest passwordRequest = new Passwordrequest { UserId = user.UserId, Token = Guid.NewGuid().ToString(), Active = true }; _repositories.PasswordRequest.Add(passwordRequest); _repositories.SaveChanges(); //send mail _emailService.Send("*****@*****.**", user.Email, "Forgot password", "Hello!"); retVal = true; } return(retVal); }
/// <summary> /// Creates a new user /// </summary> /// <param name="user"></param> /// <returns></returns> public UserModel CreateNew(UserModel user) { User newUser = new User { FirstName = user.FirstName, LastName = user.LastName, UserName = user.UserName, Email = user.Email, StatusId = UserStatus.Pending, Password = string.Empty, Userrole = user.Roles.Select(x => _repositories.Users.SetCreateVars(new Userrole { RoleId = x.RoleId })).ToList() }; _repositories.Users.Add(newUser); _repositories.SaveChanges(); user.UserId = newUser.UserId; Passwordrequest passwordRequest = new Passwordrequest { UserId = user.UserId, Token = Guid.NewGuid().ToString(), Active = true }; _repositories.PasswordRequest.Add(passwordRequest); _repositories.SaveChanges(); _emailService.Send("*****@*****.**", user.Email, "Invite Test", "Hello!"); return(user); }