public TUser CreateUserAndActivationRequest(TCreateUserForm form, Uri activateUserUrl) { var login = form.Login.Trim(); if (!EmailValidator.Validate(login)) { throw new IncorrectEmailException(); } var password = form.Password; if (!passwordValidator.Validate(password)) { throw new WeakPasswordException(); } var existingUser = userStorage.FindUserByLogin(login); if (existingUser != null) { throw new LoginAlreadyExistsException(login); } var userId = Guid.NewGuid(); var user = userProcessor.MakeUser(form, userId); SetUserPassword(user, password); userStorage.CreateUser(user); SendUserActivationRequest(user, activateUserUrl); return(userStorage.FindUser(userId)); }
public static void Generate(IUserStorage userStorage, IDemoStorage demoStorage) { var users = userStorage.GetUsers(); var students = demoStorage.GetStudents(); GroupOfStudents("Демонстраційна група", students,userStorage); var teachers = demoStorage.GetTeachers().Select(t => t) .Where(t => !users.Select(u => u.Username).Contains(t.Username)); foreach (var t in teachers) { userStorage.CreateUser(t); userStorage.AddUserToRole(Role.Teacher, t); } var courseCreators = demoStorage.GetCourseCreators().Select(cc => cc) .Where(cc => !users.Select(u => u.Username).Contains(cc.Username)); foreach (var cc in courseCreators) { userStorage.CreateUser(cc); userStorage.AddUserToRole(Role.CourseCreator, cc); } var admins = demoStorage.GetAdministrators().Select(a => a) .Where(a => !users.Select(u => u.Username).Contains(a.Username)); foreach (var admin in admins) { userStorage.CreateUser(admin); userStorage.AddUserToRole(Role.Admin, admin); } }
public static void Generate(IUserStorage userStorage, IDemoStorage demoStorage) { var users = userStorage.GetUsers(); var students = demoStorage.GetStudents(); GroupOfStudents("Демонстраційна група", students, userStorage); var teachers = demoStorage.GetTeachers().Select(t => t) .Where(t => !users.Select(u => u.Username).Contains(t.Username)); foreach (var t in teachers) { userStorage.CreateUser(t); userStorage.AddUserToRole(Role.Teacher, t); } var courseCreators = demoStorage.GetCourseCreators().Select(cc => cc) .Where(cc => !users.Select(u => u.Username).Contains(cc.Username)); foreach (var cc in courseCreators) { userStorage.CreateUser(cc); userStorage.AddUserToRole(Role.CourseCreator, cc); } var admins = demoStorage.GetAdministrators().Select(a => a) .Where(a => !users.Select(u => u.Username).Contains(a.Username)); foreach (var admin in admins) { userStorage.CreateUser(admin); userStorage.AddUserToRole(Role.Admin, admin); } }
public ActionResult Create(User user) { if (user.OpenId == null) { user.OpenId = string.Empty; } if (ModelState.IsValid) { bool error = false; if (_Storage.UsernameExists(user.Username)) { error = true; ModelState.AddModelError("Username", "User with such username already exists."); } if (!_Storage.UserUniqueIdAvailable(user.UserId, user.Id)) { error = true; ModelState.AddModelError("UserID", Localization.getMessage("Unique ID Error")); } if (!error) { _Storage.CreateUser(user); return(RedirectToAction("Index")); } } user.Password = null; //user.RolesList = _Storage.GetRoles().AsQueryable().Select(r => new SelectListItem { Text = IUDICO.UserManagement.Localization.getMessage(r.ToString()), Value = ((int)r).ToString(), Selected = false }); return(View(user)); }
public void CreateUser() { const string userId = "UniqueUserId_CreateUser"; const string username = userId + "_"; Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(Tests.Storage.GetUser(u => u.Username == "panza")); Storage.CreateUser(new User { Name = "Create User", Username = username, Password = "******", UserId = userId }); var created = Storage.GetUser(u => u.Username == username); Assert.AreEqual(created.UserId, userId); Storage.DeleteUser(u => u.Username == username); }
public static void GenerateForTestingSystemSeleniumTests(IUserStorage userStorage, IDemoStorage demoStorage) { var students = new List <User> { new User { Username = "******", Password = "******", Email = "*****@*****.**", OpenId = "*****@*****.**", Name = "SeleniumStudent" }, }.Select(t => t).Where(t => !userStorage.GetUsers().Select(u => u.Username).Contains(t.Username)); GroupOfStudents("Selenium testing system group", students, userStorage); User userWithoutGroup = new User { Username = "******", Password = "******", Email = "*****@*****.**", OpenId = "*****@*****.**", Name = "SeleniumStudent2" }; if (userStorage.CreateUser(userWithoutGroup)) { userStorage.AddUserToRole(Role.Student, userWithoutGroup); } var teachers = new List <User> { new User() { Username = "******", Password = "******", Email = "*****@*****.**", OpenId = "*****@*****.**", Name = "SeleniumTeacher" } }.Select(t => t).Where(t => !userStorage.GetUsers().Select(u => u.Username).Contains(t.Username)); foreach (var t in teachers) { userStorage.CreateUser(t); userStorage.AddUserToRole(Role.Teacher, t); } }
public void DoWork() { var newUser = user_.CreateUser("ed"); UserRegistration r = new UserRegistration(user_, email_); r.Register(newUser); }
public static void GenerateForTestingSystemSeleniumTests(IUserStorage userStorage, IDemoStorage demoStorage) { var students = new List<User> { new User { Username = "******", Password = "******", Email = "*****@*****.**", OpenId = "*****@*****.**", Name = "SeleniumStudent" }, }.Select(t => t).Where(t => !userStorage.GetUsers().Select(u => u.Username).Contains(t.Username)); GroupOfStudents("Selenium testing system group",students,userStorage); User userWithoutGroup = new User { Username = "******", Password = "******", Email = "*****@*****.**", OpenId = "*****@*****.**", Name = "SeleniumStudent2" }; if (userStorage.CreateUser(userWithoutGroup)) { userStorage.AddUserToRole(Role.Student, userWithoutGroup); } var teachers = new List<User>{ new User() { Username = "******", Password = "******", Email = "*****@*****.**", OpenId = "*****@*****.**", Name = "SeleniumTeacher" } }.Select(t => t).Where(t => !userStorage.GetUsers().Select(u => u.Username).Contains(t.Username)); foreach (var t in teachers) { userStorage.CreateUser(t); userStorage.AddUserToRole(Role.Teacher, t); } }
public MembershipCreateStatus CreateUser(string username, string password, string email, string openId, bool isApproved) { try { var user = new User { Username = username, Password = password, Email = email, IsApproved = isApproved }; _UserStorage.CreateUser(user); return(MembershipCreateStatus.Success); } catch (Exception) { return(MembershipCreateStatus.ProviderError); } }
public static void GroupOfStudents(string groupName, IEnumerable <User> students, IUserStorage userStorage) { Group demoGroup = new Group { Name = groupName }; if (!userStorage.GetGroups().Select(g => g.Name).Contains(demoGroup.Name)) { userStorage.CreateGroup(demoGroup); } else { demoGroup.Id = userStorage.GetGroups().FirstOrDefault(g => g.Name == demoGroup.Name).Id; } foreach (var stud in students.Select(s => s).Where(s => !userStorage.GetUsers().Select(u => u.Username).Contains(s.Username))) { userStorage.CreateUser(stud); userStorage.AddUserToRole(Role.Student, stud); userStorage.AddUserToGroup(demoGroup, stud); } }
public static void GroupOfStudents(string groupName, IEnumerable<User> students, IUserStorage userStorage) { Group demoGroup = new Group { Name = groupName }; if (!userStorage.GetGroups().Select(g => g.Name).Contains(demoGroup.Name)) { userStorage.CreateGroup(demoGroup); } else { demoGroup.Id = userStorage.GetGroups().FirstOrDefault(g => g.Name == demoGroup.Name).Id; } foreach (var stud in students.Select(s => s).Where(s => !userStorage.GetUsers().Select(u => u.Username).Contains(s.Username))) { userStorage.CreateUser(stud); userStorage.AddUserToRole(Role.Student, stud); userStorage.AddUserToGroup(demoGroup, stud); } }