public SubmitResult Submit(int userId, string role) { try { var user = _userManager.GetAllUsers().First(u => u.UserId == userId); EnsureCanSubmit(user); var reader = _readerManager.GetReaderByEmail(user.Email); _userManager.ConfirmUserWithReader(userId, reader.ReaderId, role); } catch (Exception e) { return(new SubmitResult { Success = false, ErrorMessage = e.Message }); } return(new SubmitResult { Success = true }); }
public List <UsersConfirmationModel> CreateListOfUnconfirmedUsers(string[] allUnconfirmedUsers) { List <UsersConfirmationModel> list = new List <UsersConfirmationModel>(); foreach (var item in allUnconfirmedUsers) { UserProfileBusinessModel user = usersFacade.GetUserByUserName(item); ReaderBusinessModel readerBusiness = readerManager.GetReaderByEmail(user.Email); UsersConfirmationModel listItem = new UsersConfirmationModel { CoincidedReaderBusiness = readerBusiness, UnconfirmedUser = user }; list.Add(listItem); } return(list); }
public ActionResult Register(RegisterModel model) { var reader = _readerManager.GetReaderByEmail(model.Email); var users = _userManager.GetAllUsers(); if (reader == null) { ModelState.AddModelError("Email", "There is no such reader profile"); } if (users.Any(u => u.UserName == model.UserName)) { ModelState.AddModelError("UserName", "Already exists"); } if (users.Any(u => u.Email == model.Email)) { ModelState.AddModelError("Email", "Already exists"); } if (ModelState.IsValid) { // Attempt to register the user try { WebSecurity.CreateUserAndAccount(model.UserName, model.Password, new { Email = model.Email }); Roles.AddUserToRole(model.UserName, "Unregistered"); WebSecurity.Login(model.UserName, model.Password); return(RedirectToAction("Index", "Home")); } catch (MembershipCreateUserException e) { ModelState.AddModelError("", ErrorCodeToString(e.StatusCode)); } } // If we got this far, something failed, redisplay form return(View(model)); }