Esempio n. 1
0
        public IActionResult Register(UserRegisterInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            User user = new User
            {
                Username = model.Username,
                Password = this.HashPassword(model.Password),
                Email    = model.Email
            };

            var createdUser = this.userService.CreateUser(user);

            this.SignIn(createdUser.Id, model.Username, model.Password);

            return(this.Redirect("/"));
        }
        public IActionResult Register(UserRegisterInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            User user = new User
            {
                Username = model.Username,
                Password = this.HashPassword(model.Password),
                Email    = model.Email
            };

            this.userService.CreateUser(user);
            this.orderService.CreateOrder(new Order {
                CashierId = user.Id
            });

            return(this.Redirect("/Users/Login"));
        }
        public async Task <IActionResult> Register([FromBody] UserRegisterInputModel registerModel)
        {
            ApplicationUser user = new ApplicationUser
            {
                UserName = registerModel.Username,
                Email    = registerModel.Email,
            };

            var createResult = await _userManager.CreateAsync(user, registerModel.Password);

            var tokenEndpoint    = new UriBuilder(Request.Scheme, Request.Host.Host, Request.Host.Port.GetValueOrDefault(), "/connect/token");
            var userInfoEndpoint = new UriBuilder(Request.Scheme, Request.Host.Host, Request.Host.Port.GetValueOrDefault(), "/connect/userinfo");

            var result = new UserRegisterOutputModel()
            {
                Username      = user.UserName,
                EmailAddress  = user.Email,
                Registered    = true,
                TokenEndPoint = tokenEndpoint.ToString()
            };

            if (createResult.Succeeded)
            {
                return(Created(userInfoEndpoint.Uri, result));
            }

            return(BadRequest(createResult.Errors.FirstOrDefault()?.Description));
        }
Esempio n. 4
0
        public HttpResponse Register(UserRegisterInputModel model)
        {
            if (IsUserSignedIn())
            {
                return(Redirect("/"));
            }

            var validation = ValidationHelper.IsValid(model);

            if (!validation.result)
            {
                return(Error(validation.errorMessage));
            }

            if (!_userService.IsUsernameAvailable(model.Username))
            {
                return(Error("Username is not available!"));
            }

            if (!_userService.IsEmailAvailable(model.Email))
            {
                return(Error("Email is not available!"));
            }

            _userService.RegisterUser(model);

            return(Redirect("/Users/Login"));
        }
Esempio n. 5
0
        public IActionResult Register(UserRegisterInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                ModelState.Add(string.Empty, "The passwords must match");
                return(Redirect("/Users/Register"));
            }

            if (userService.GetUserByUsernameOrEmail(model.Username, model.Email) != null)
            {
                return(Redirect("/Users/Register"));
            }

            User user = new User
            {
                Username = model.Username,
                Email    = model.Email,
                Password = passwordService.HashPassword(model.Password)
            };

            userService.CreateUser(user);
            SignIn(user.Id, user.Username, user.Email);

            return(this.Redirect("/"));
        }
        public HttpResponse Register(UserRegisterInputModel model)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/Trips/All"));
            }

            if (string.IsNullOrEmpty(model.Username) || model.Username.Length < 5 || model.Username.Length > 20)
            {
                return(this.Error("Username should be between 5 and 20 characters."));
            }

            if (string.IsNullOrEmpty(model.Email) || !new EmailAddressAttribute().IsValid(model.Email))
            {
                return(this.Error("Invalid email."));
            }

            if (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6 || model.Password.Length > 20)
            {
                return(this.Error("Password should be between 6 and 20 characters."));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(this.Error("Passwords do not match."));
            }

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

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 7
0
        public HttpResponse Register(UserRegisterInputModel user)
        {
            if (IsUserSignedIn())
            {
                return(Redirect("/"));
            }

            var(result, errorMessage) = ValidationHelper.IsValid(user);
            if (!result)
            {
                return(Error(errorMessage));
            }

            if (!_userService.IsUsernameAvailable(user.Username))
            {
                return(Error("Username is not available!"));
            }

            if (!_userService.IsEmailAvailable(user.Email))
            {
                return(Error("Email is not available!"));
            }

            _userService.AddUser(user.Username, user.Email, user.Password);

            return(Redirect("/Users/Login"));
        }
Esempio n. 8
0
        public HttpResponse Register(UserRegisterInputModel model)
        {
            if (!ModelStateValidator.IsValid(model))
            {
                return(this.View());
            }

            this.userService.Create(model.Username, model.Email, model.Password, model.UserType);

            return(this.Redirect(nameof(this.Login)));
        }
Esempio n. 9
0
        public IActionResult Register(UserRegisterInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Users/Register"));
            }

            var userId = this.userService.CreateUser(inputModel.Username, inputModel.Email, inputModel.Password);

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 10
0
        public void RegisterUser(UserRegisterInputModel model)
        {
            var user = new User
            {
                Email    = model.Email,
                Password = ComputeHash(model.Password),
                Username = model.Username
            };

            _dbContext.Users.Add(user);
            _dbContext.SaveChanges();
        }
Esempio n. 11
0
        public void Create(UserRegisterInputModel input)
        {
            var user = new User
            {
                Username   = input.Username,
                Email      = input.Email,
                Password   = ComputeHash(input.Password),
                IsMechanic = input.UserType == "Mechanic" ? true : false,
            };

            this.db.Users.Add(user);

            this.db.SaveChanges();
        }
Esempio n. 12
0
        public IActionResult Register(UserRegisterInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            this.usersService.CreateUser(model.Username, model.Email, model.Password);
            return(this.Redirect("/Users/Login"));
        }
Esempio n. 13
0
        public string RegisterUser(UserRegisterInputModel model)
        {
            var user = new User()
            {
                Email    = model.Email,
                Username = model.Username,
                Password = ComputeHash(model.Password),
                Role     = IdentityRole.User,
                Id       = Guid.NewGuid().ToString()
            };

            _dbContext.Users.Add(user);
            _dbContext.SaveChanges();

            return(user.Id);
        }
Esempio n. 14
0
        public HttpResponse Register(UserRegisterInputModel model)
        {
            if (this.IsUserLoggedIn())
            {
                return(this.Redirect("/"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (model.Username?.Length < 5 || model.Username?.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (model.Email?.Length < 5 || model.Email?.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (!this.IsValidEmail(model.Email))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (string.IsNullOrWhiteSpace(model.Password))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (this.usersService.IsEmailUsed(model.Email))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (this.usersService.IsUsernameUsed(model.Username))
            {
                return(this.Redirect("/Users/Register"));
            }

            this.usersService.Create(model.Username, model.Email, model.Password);

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 15
0
        public async Task <ApplicationUser> RegisterAsync(UserRegisterInputModel input)
        {
            var hashedPassword = this.utilitiesService.HashPassword(input.Password);

            var user = new ApplicationUser()
            {
                Email    = input.Email,
                Username = input.Username,
                Password = hashedPassword
            };

            await this.dbContext.Users.AddAsync(user);

            await this.dbContext.SaveChangesAsync();

            return(user);
        }
Esempio n. 16
0
        public HttpResponse Register(UserRegisterInputModel inputModel)
        {
            if (this.IsUserLoggedIn())
            {
                return(this.Redirect("/"));
            }

            if (inputModel.Username?.Length < 5 || inputModel.Username?.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (string.IsNullOrWhiteSpace(inputModel.Email))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (!this.IsValidEmail(inputModel.Email))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (inputModel.Password?.Length < 6 || inputModel.Password?.Length > 20)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (inputModel.Password != inputModel.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (this.usersService.IsUsernameExists(inputModel.Username))
            {
                return(this.Redirect("/Users/Register"));
            }

            if (this.usersService.IsEmailExists(inputModel.Email))
            {
                return(this.Redirect("/Users/Register"));
            }

            this.usersService.Register(inputModel.Username, inputModel.Email, inputModel.Password);

            return(this.Redirect("/Users/Login"));
        }
        public HttpResponse Register(UserRegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

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

            if (string.IsNullOrWhiteSpace(input.Username) || input.Username.Length < 4 || input.Username.Length > 20)
            {
                return(this.Error("Username is required and should be between 4 and 20 characters!"));
            }

            if (string.IsNullOrWhiteSpace(input.Email))
            {
                return(this.Error("Email address is required!"));
            }

            if (!new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Email address is not valid"));
            }

            if (string.IsNullOrWhiteSpace(input.Password) || input.Password.Length < 4 || input.Password.Length > 20)
            {
                return(this.Error("Password is required and should be between 5 and 20 characters!"));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("Entered Username already exists! Please try again with different username!"));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("Entered email already exists! Please try again with different email!"));
            }

            this.usersService.Create(input);

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 18
0
        public ActionResult Register(UserRegisterInputModel inputUserModel)
        {
            if (inputUserModel.Password != inputUserModel.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            User user = new User
            {
                Username = inputUserModel.Username,
                Password = this.HashPassword(inputUserModel.Password),
                Email    = inputUserModel.Email
            };

            this.userService.CreateUser(user);

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 19
0
        public async Task <IActionResult> Register(UserRegisterInputModel userRegister)
        {
            if (userRegister.Password != userRegister.ConfirmPassword)
            {
                return(this.Redirect("Users/Register"));
            }

            ApplicationUser user = new ApplicationUser
            {
                UserName     = userRegister.Username,
                PasswordHash = this.HashPassword(userRegister.Password),
                Email        = userRegister.Email,
            };

            await this.userService.CreateUserAsync(user);

            return(this.Redirect("/Users/Login"));
        }
        public async Task <IActionResult> SignUp([FromBody] UserRegisterInputModel inputModel)
        {
            var user = new User()
            {
                UserName = inputModel.Username,
                Email    = inputModel.Email,
            };

            var userCreatedResult = await this.userManager.CreateAsync(user, inputModel.Password);

            if (userCreatedResult.Succeeded)
            {
                await this.SendEmailValidation(user);

                return(this.Ok());
            }

            return(this.BadRequest(userCreatedResult.Errors));
        }
        public IActionResult Register(UserRegisterInputModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/Users/Register"));
            }

            if (model.Password != model.ConfirmPassword)
            {
                return(this.Redirect("/Users/Register"));
            }

            var user = ModelMapper.ProjectTo <User>(model);

            user.Password = this.HashPassword(model.Password);

            this.userService.CreateUser(user);

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 22
0
        public UserDto Create(IUserInputModel inputModel)
        {
            UserRegisterInputModel userRegisterInputModel = (UserRegisterInputModel)inputModel;

            NullCheck(userRegisterInputModel);
            try
            {
                UserDto userDto = new UserDto(userRegisterInputModel.Password, userRegisterInputModel.Email);
                return(userDto);
            }
            catch (Exception ex)
            {
                throw new BusinessOperationException(new BusinesOperationExceptionModel
                {
                    ClassName       = "UserRegisterInputBusinessOperation",
                    MethodName      = "Create",
                    OriginalMessage = ex.Message
                }, ex);
            }
        }
Esempio n. 23
0
        public HttpResponse Register(UserRegisterInputModel input)
        {
            if (string.IsNullOrWhiteSpace(input.EmailAddress))
            {
                return(this.Error("Email cannot be empty!"));
            }

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


            if (input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username must be between  5 and  20 characters long."));
            }


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



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


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

            this.usersService.Register(input.Username, input.EmailAddress, input.Password);

            return(this.Redirect("/Users/Login"));
        }
Esempio n. 24
0
        public IActionResult Register(UserRegisterInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect("/User/Register"));
            }

            if (inputModel.Password != inputModel.ConfirmPassword)
            {
                return(this.Redirect("/User/Register"));
            }

            this.context.Users.Add(new PandaUser
            {
                UserName     = inputModel.Username,
                PasswordHash = inputModel.Password
            });

            this.context.SaveChanges();
            return(this.Redirect("/User/Login"));
        }
Esempio n. 25
0
        public static ValidatorResult ValidateRegister(UserRegisterInputModel input)
        {
            var result = new ValidatorResult();

            if (!Validator.ValidateEmail(input.Email))
            {
                result.AddErrorMessage("Invalid email");
            }

            if (!Validator.ValidateUsername(input.Username))
            {
                result.AddErrorMessage("Invalid username");
            }

            if (!Validator.ValidatePassword(input.Password))
            {
                result.AddErrorMessage("Invalid password");
            }

            return(result);
        }
Esempio n. 26
0
        public async Task <IActionResult> Register(UserRegisterInputModel input)
        {
            var response = new ResponseModel();

            if (!ModelState.IsValid)
            {
                var errorMessages = this.utilitiesService.GetModelStateErorrs(ModelState);
                foreach (var message in errorMessages)
                {
                    response.AddErrorMessage(message);
                }
                response.StatusCode = 400;
                return(Json(response));
            }

            var isEmailAvailable = this.usersService.IsEmailAvailable(input.Email);

            if (isEmailAvailable == false)
            {
                response.AddErrorMessage("This email is already taken");
                response.StatusCode = 400;
                return(Json(response));
            }

            var isUsernameAvailable = this.usersService.IsUsernameAvailable(input.Username);

            if (isUsernameAvailable == false)
            {
                response.AddErrorMessage("This username is already taken");
                response.StatusCode = 400;
                return(Json(response));
            }

            var user = await this.usersService.RegisterAsync(input);

            var tokens = await this.tokenAuthService.GenerateTokensAsync(user);

            response.Data = tokens;
            return(Json(response));
        }
Esempio n. 27
0
        public HttpResponse Register(UserRegisterInputModel input)
        {
            if (this.IsUserSignedIn())
            {
                return(this.Redirect("/"));
            }

            if (string.IsNullOrEmpty(input.Username) || input.Username.Length < 5 || input.Username.Length > 20)
            {
                return(this.Error("Username should be between 5 and 20 characters."));
            }

            if (string.IsNullOrEmpty(input.Email) || !new EmailAddressAttribute().IsValid(input.Email))
            {
                return(this.Error("Invalid email address."));
            }

            if (string.IsNullOrEmpty(input.Password) || input.Password.Length < 6 || input.Password.Length > 20)
            {
                return(this.Error("Password should be between 6 and 20 characters."));
            }

            if (input.ConfirmPassword != input.Password)
            {
                return(this.Error("Both passwords are different."));
            }

            if (!this.usersService.IsUsernameAvailable(input.Username))
            {
                return(this.Error("This username is already taken."));
            }

            if (!this.usersService.IsEmailAvailable(input.Email))
            {
                return(this.Error("This email address is already taken."));
            }

            this.usersService.CreateUser(input.Username, input.Email, input.Password);
            return(this.Redirect("/Users/Login"));
        }
        public async Task <IActionResult> Register(UserRegisterInputModel input)
        {
            if (ModelState.IsValid == false)
            {
                return(this.BadRequest());
            }

            if (input.Password != input.RepeatPassword)
            {
                return(this.BadRequest());
            }

            if (this.usersService.IsUsernameUsed(input.Username))
            {
                this.TempData["UsernameTaken"] = "Username already taken";
                return(View(input));
            }

            await this.usersService.CreateAsync(input.Username, input.Password);

            return(this.Redirect(nameof(Login)));
        }
Esempio n. 29
0
        public async Task <UserRegisterOutputModel> Register([FromBody] UserRegisterInputModel registerModel)
        {
            ApplicationUser user = new ApplicationUser
            {
                UserName = registerModel.Username,
                Email    = registerModel.Email,
            };

            var createResult = await userManager.CreateAsync(user, registerModel.Password);

            if (createResult.Succeeded)
            {
                return(new UserRegisterOutputModel {
                    Error = false
                });
            }

            return(new UserRegisterOutputModel
            {
                Error = true,
                ErrorMessage = createResult.Errors.FirstOrDefault()?.Description,
            });
        }
Esempio n. 30
0
        public HttpResponse Register(UserRegisterInputModel model)
        {
            var validation = model.IsValid();

            if (!validation.isSuccessful)
            {
                return(Error(validation.errorMessage));
            }

            if (!_userService.IsEmailAvailable(model.Email))
            {
                return(Error("Email is taken"));
            }

            if (!_userService.IsUsernameAvailable(model.Username))
            {
                return(Error("Username is taken"));
            }

            _userService.RegisterUser(model);

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