示例#1
0
        public async Task <IActionResult> RegisterRequest(RegisterViewModel user, string button, CancellationToken cancellationToken = default)
        {
            if (!button.Equals("register"))
            {
                return(View("Register"));
            }


            if (string.IsNullOrEmpty(user.Email) || string.IsNullOrWhiteSpace(user.Email))
            {
                user.EmailError = "Enter email!";
            }

            if (string.IsNullOrEmpty(user.Password) || string.IsNullOrWhiteSpace(user.Password))
            {
                user.PasswordError = "Enter password!";
            }

            if (string.IsNullOrEmpty(user.Username) || string.IsNullOrWhiteSpace(user.Username))
            {
                user.UsernameError = "Enter username!";
            }

            if (string.IsNullOrEmpty(user.PhoneNumber) || string.IsNullOrWhiteSpace(user.PhoneNumber))
            {
                user.PhoneNumberError = "Enter phone!";
            }

            PhotoCaptcha capPhoto = await _photoRepository.GetAsync(user.CaptchaId);

            if (!capPhoto.Answer.Equals(user.CaptchaAnswer))
            {
                user.CaptchaError = "Captcha was wrong!";
            }

            user.Captcha = capPhoto;

            var user_email = await _userManager.FindByEmailAsync(user.Email);

            if (user_email != null)
            {
                user.EmailError = "User with such email already exists";
            }

            if (user.CaptchaError == null && user.EmailError == null && user.PasswordError == null && user.UsernameError == null && user.PhoneNumberError == null)
            {
                await _userManager.CreateAsync(_mapper.Map <IdentityUser>(user), user.Password);

                await _identityContext.SaveChangesAsync(cancellationToken);

                await _userManager.AddToRoleAsync(await _userManager.FindByEmailAsync(user.Email), "User");

                return(Redirect(user.ReturnUrl + "registration"));
            }
            else
            {
                return(PartialView("Register", user));
            }
        }
示例#2
0
        public async Task <IActionResult> Register(LoginViewModel model)
        {
            var data = await _photoRepository.GetAllAsync();

            IReadOnlyCollection <PhotoCaptcha> photo = data.ToList();
            PhotoCaptcha p = photo.First();

            return(PartialView(new RegisterViewModel {
                ReturnUrl = model.ReturnUrl, CaptchaId = p.Id, Captcha = new PhotoCaptcha {
                    Data = p.Data
                }
            }));
        }