Exemplo n.º 1
0
        // asdasdasd.wdasdasdasd.asdasdasdas

        public void Register(RegisterModelForRoomate request)
        {
            if (string.IsNullOrWhiteSpace(request.Password) ||
                string.IsNullOrWhiteSpace(request.ConfirmPassword))
            {
                throw new UserException(null, request.Password,
                                        "Password is required");
            }

            if (request.Password != request.ConfirmPassword)
            {
                throw new UserException(null, request.Password,
                                        "Passwords does not match");
            }

            if (string.IsNullOrWhiteSpace(request.FullName))
            {
                throw new UserException(null, request.FullName,
                                        "FullName is required"); // should use custom exception
            }

            if (string.IsNullOrWhiteSpace(request.Address))
            {
                throw new UserException(null, request.Address,
                                        "Address is required");
            }


            var hashedPassword = HashPassword(request.Password);

            var user = new User
            {
                FullName           = request.FullName,
                Address            = request.Address,
                Password           = hashedPassword,
                Age                = request.Age,
                DoYouHaveSpace     = request.DoYouHaveSpace,
                Email              = request.Email,
                Messages           = request.Messages,
                PhoneNumber        = request.PhoneNumber,
                QuestionForRoomate = request.QuestionForRoomate
            };

            _userRepository.Insert(user);
        }
Exemplo n.º 2
0
        // asdasdasd.wdasdasdasd.asdasdasdas

        public void Register(RegisterModelForRoomate request)
        {
            if (string.IsNullOrWhiteSpace(request.Password) ||
                string.IsNullOrWhiteSpace(request.ConfirmPassword))
            {
                throw new UserException(null, request.Password,
                                        "Password is required");
            }

            if (request.Password != request.ConfirmPassword)
            {
                throw new UserException(null, request.Password,
                                        "Passwords does not match");
            }

            if (string.IsNullOrWhiteSpace(request.FullName))
            {
                throw new UserException(null, request.FullName,
                                        "FullName is required"); // should use custom exception
            }

            if (string.IsNullOrWhiteSpace(request.Address))
            {
                throw new UserException(null, request.Address,
                                        "Address is required");
            }

            /*  if (string.(request.Age))
             * {
             *    throw new UserException(null, request.Age,
             *        "Age is required");
             * }*/

            var hashedPassword = HashPassword(request.Password);

            var user = new User
            {
                FullName = request.FullName,
                Address  = request.Address,
                Password = hashedPassword,
                Age      = request.Age
            };

            _userRepository.Insert(user);
        }
Exemplo n.º 3
0
        public IActionResult Register([FromBody] RegisterModelForRoomate request)
        {
            try
            {
                _userService.Register(request);

                Log.Information("USER: {username} has registered", request.FullName);
                //Debug.WriteLine($"User registered with {request.Username}");
                return(Ok("Success"));
            }
            catch (UserException ex)
            {
                Log.Error($"USER: {ex.UserId}.{ex.Name}: {ex.Message}");
                //Debug.WriteLine($"User {ex.UserId}.{ex.Name}: {ex.Message}");
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                Log.Error($"USER: {ex.Message}");
                //Debug.WriteLine($"Unknown error: {ex.Message}");
                return(BadRequest(ex.Message));
            }
        }