public void CreateUser(string username, string email, string manager, string password, string[] roleNames, int householdId, bool defaultPassword, bool login) { Exception exception; var errors = String.Empty; if (String.IsNullOrWhiteSpace(email)) throw new Exception("Email must have a value."); if (String.IsNullOrWhiteSpace(password)) throw new Exception("Password must have a value."); if(password.Length < 6) throw new Exception("Password must have at least 6 characters."); if (LunaLogic.Current.DatabaseProvider.Users.Search(username, "Username").Any()) throw new Exception("Your username is already taken!"); if (LunaLogic.Current.DatabaseProvider.Users.Search(email, "Email").Any()) throw new Exception("Your email address is already taken!"); if (String.IsNullOrWhiteSpace(username)) username = email; if (!defaultPassword) password = Pbkdf2Provider.Hash(password); var user = new User { Email = email, Password = password, Username = username, HouseHoldId = householdId, LastActivityDate = DateTime.UtcNow, }; LunaLogic.Current.DatabaseProvider.Users.Insert(user, manager, roleNames, out exception); if (exception != null) throw exception; if (login) FormsAuthentication.SetAuthCookie(user.Username, true); if (!String.IsNullOrWhiteSpace(errors)) throw new Exception("1 or more error(s) occured. " + errors); }
public UserPermissionsModel(User user, List<PermissionModel> permissions) { User = user; Permissions = permissions; }
private static UserDetails CreateUserDetails(User user) { var cu = new UserDetails( user.Email, "FormsAuthentication", true, user.Username, user.Permissions.Select(x => x.PermissionName).ToList()); return cu; }