public async Task <IActionResult> Register([FromBody] RegistrationInputViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var result = await _users.Register(model);

            if (!result.Succeeded)
            {
                return(BadRequest(Errors.AddErrorsToModelState(result, ModelState)));
            }

            return(Ok("Account created"));
        }
Exemplo n.º 2
0
        public async Task <IdentityResult> Register(RegistrationInputViewModel model)
        {
            var userIdentity = new ApplicationUser {
                UserName = model.Username
            };

            var result = await _users.CreateAsync(userIdentity, model.Password);

            if (!result.Succeeded)
            {
                return(result);
            }

            // Add new user as Creator
            await _context.Creators.AddAsync(new CreatorUser { IdentityId = userIdentity.Id });

            await _context.SaveChangesAsync();

            return(result);
        }
Exemplo n.º 3
0
        public HttpResponse Register(RegistrationInputViewModel input)
        {
            if (input.Username.Length < 4 || input.Username.Length > 10)
            {
                return(this.Error("Username must be at least 4 characters and at most 10"));
            }

            if (input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password must be at least 6 characters and at most 20"));
            }

            if (input.Password != input.ConfirmPassword)
            {
                return(this.Error("Password should match."));
            }

            if (this.usersService.EmailExists(input.Email))
            {
                return(this.Error("Email already in use."));
            }

            if (this.usersService.UsernameExists(input.Username))
            {
                return(this.Error("Username already in use."));
            }

            if (string.IsNullOrWhiteSpace(input.Email))
            {
                return(this.Error("Email cannot be empty!"));
            }

            this.usersService.CreateUser(input.Username, input.Password, input.Email);

            return(this.Redirect("/Users/Login"));
        }