Exemple #1
0
        public JsonResult Registration(RegistrationModel model)
        {
            JSONResult accountResult = new JSONResult();

            try
            {
                if (ModelState.IsValid && model.IsValid())
                {
                    if (!AuthWrapper.UserExist(model.PhoneNumber))
                    {
                        var newUser = new User
                        {
                            FirstName        = model.FirstName,
                            SecondName       = model.SecondName,
                            PhoneNumber      = model.PhoneNumber,
                            Password         = model.Password,
                            RegistrationDate = DateTime.Now
                        };

                        var isSaveUser = AuthWrapper.AddNewUser(newUser);

                        if (isSaveUser)
                        {
                            var userId = AuthWrapper.GetUserIdByLogin(model.PhoneNumber);

                            DataWrapper.AddCashUser(userId);
                            FormsAuthentication.SetAuthCookie(model.PhoneNumber, true);
                            accountResult.SetIsSuccess(GetUrlRedirect(model.PhoneNumber));
                        }
                        else
                        {
                            accountResult.SetNotSuccess(ErrorMessages.UnknownError);
                        }
                    }
                    else
                    {
                        accountResult.SetNotSuccess(ErrorMessages.ExistentPhoneNumber);
                    }
                }
                else
                {
                    if (!model.IsValid())
                    {
                        accountResult.SetNotSuccess(ErrorMessages.NotFullDataRegistration);
                    }
                    else
                    {
                        accountResult.SetNotSuccess(ErrorMessages.UnknownError);
                    }
                }
            }
            catch (Exception ex)
            {
                accountResult.SetNotSuccess(ErrorMessages.UnknownError);
                logger.Error("Method Registration: ", ex);
            }

            return(Json(accountResult, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public async Task <bool> RegisterAsync(RegistrationModel model)
        {
            //Server call simulation
            await Task.Delay(2000);

            var result = model.IsValid();

            if (result)
            {
                model.Email    = EmailDemo;
                model.Password = PasswordDemo;
            }

            return(result);
        }
Exemple #3
0
        public async Task <IActionResult> Registration([FromBody] RegistrationModel userModel)
        {
            var user = new ApplicationUser {
                UserName = userModel.UserName,
                Email    = userModel.Email
            };

            _logger.LogDebug($"Registration: UserName:{user.UserName}, Email:{user.Email}");
            if (userModel.IsValid(_userManager, user, out var error))
            {
                _logger.LogDebug($"Registration: Model is valid");

                var result = await _userManager.CreateAsync(user, userModel.Password);

                if (result.Succeeded)
                {
                    _logger.LogDebug($"Registration: Create user is Succeeded");

                    //var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);
                    //var callbackUrl = Url.EmailConfirmationLink(user.Id, code, Request.Scheme);
                    //await _emailSender.SendEmailConfirmationAsync(model.Email, callbackUrl);

                    await _context.AddNewUserAsync(user.Id);

                    await _userManager.AddToRoleAsync(user, Roles.User);

                    await _signInManager.SignInAsync(user, isPersistent : true);

                    return(Ok(_service.SuccessUserAuth(user.UserName, Roles.User)));
                }
                else
                {
                    _logger.LogDebug($"Registration: Create user is Failure");

                    // TODO: can't create
                    // return error description
                    return(BadRequest(result.Errors.FirstOrDefault()?.Description ?? "Please try again"));
                }
            }
            _logger.LogDebug($"Registration: Model is invalid");

            // TODO: not valid
            // return error description
            return(BadRequest(error.Description ?? "Please try again"));
        }
Exemple #4
0
 public bool isValid()
 {
     if (isLogin == "true")
     {
         if (LoginModel.IsValid() == "true")
         {
             return(true);
         }
     }
     else
     {
         if (RegistrationModel.IsValid() == "true")
         {
             return(true);
         }
     }
     return(false);
 }