Exemple #1
0
 public MethodResult<string> RegisterUser(RegisterUser registerUser)
 {
     if (Db.LoginIsNotUnique(registerUser.Login))
         return new MethodResult<string> { ErrorMessage = Messages.LoginAlreadyUsed };
     if (Db.EmailIsNotUnique(registerUser.Email))
         return new MethodResult<string> { ErrorMessage = Messages.EmailAlreadyUsed };
     registerUser.RegistrationCode = RandomHelper.GetRandomString(10);
     var user = new User();
     ReflectionHelper.CopyAllProperties(registerUser, user);
     Db.Save(user);
     return new MethodResult<string>(user.RegistrationCode);
 }
Exemple #2
0
 public ActionResult Register(RegisterUser user)
 {
     if (ModelState.IsValid)
     {
         user.Password = CryptHelper.GetSha512Base64Hash(user.Login.ToLower() + user.Password);
         var result = ServiceProxySingleton.Instance.RegisterUser(user);
         if (result.IsError())
             ModelState.AddModelError("", result.ErrorMessage);
         else
         {
             user.RegistrationCode = result.AttachedObject;
             var helper = new EmailController("ConfirmEmail", new PasswordMailInfo {UserName = user.UserFio ?? user.Login, Email = user.Email, Code = user.RegistrationCode});
             helper.SendConfirmEmail();
             ViewBag.Success = true;
         }
     }
     else
     {
         var errors =
             ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage).Distinct().ToArray();
         foreach (var e in errors)
             ModelState.AddModelError("", e);
     }
     return View(user);
 }
 public MethodResult<string> RegisterUser(RegisterUser user)
 {
     return SendPostRequest<MethodResult<string>, RegisterUser>("registerUser", user);
 }