Exemple #1
0
        public IActionResult Login([FromBody] LoginViewModel loginViewModel)
        {
            if (string.IsNullOrEmpty(loginViewModel.Email) && string.IsNullOrEmpty(loginViewModel.Password))
            {
                return(Unauthorized());
            }
            CinemaUserDTO userByEmail = _userLogic.GetUserByEmail(loginViewModel.Email);

            if (userByEmail != null && userByEmail.Password.Equals(_accountLogic.EncryptPassword(loginViewModel.Password)))
            {
                int      minutesToExpire = loginViewModel.RememberMe ? 1440 : 60;
                DateTime expirationDate  = DateTime.Now.AddMinutes(minutesToExpire);
                Guid     token           = Guid.NewGuid();
                _accountLogic.AddToken(new TokenDTO {
                    AccessToken    = token.ToString(),
                    ExpirationDate = expirationDate,
                    UserId         = userByEmail.UserId
                });
                HttpContext.Response.Cookies.Append("AuthenticationToken", token.ToString(), new CookieOptions {
                    Expires = expirationDate
                });
                return(Ok());
            }

            return(NotFound());
        }
Exemple #2
0
        public IActionResult EditProfile()
        {
            CinemaUserDTO userDto = _userLogic.GetUserById(_accountLogic.GetCurentUserId());
            UserViewModel model   = _accountControllerHelper.BuildViewModel(userDto);

            return(View("EditProfile", model));
        }
 public UserViewModel BuildViewModel(CinemaUserDTO userDto)
 {
     return(new UserViewModel {
         FirstName = userDto.FirstName,
         LastName = userDto.LastName,
         PhoneNumber = userDto.PhoneNumber,
         UserId = userDto.UserId,
         Email = userDto.Email
     });
 }
Exemple #4
0
        public bool EditUser(CinemaUserDTO cinemaUserDTO)
        {
            bool success = _userRepository.EditUser(cinemaUserDTO);

            if (cinemaUserDTO.RoleName != null && _userRepository.GetRoleByUserId(cinemaUserDTO.UserId).FirstOrDefault().Role != cinemaUserDTO.RoleName)
            {
                _userRepository.ChangeUserRole(cinemaUserDTO.UserId, cinemaUserDTO.RoleName);
            }
            return(success);
        }
Exemple #5
0
 public UserViewModel BuildViewModel(CinemaUserDTO cinemaUserDTO)
 {
     return(new UserViewModel {
         UserId = cinemaUserDTO.UserId,
         FirstName = cinemaUserDTO.FirstName,
         LastName = cinemaUserDTO.LastName,
         Email = cinemaUserDTO.Email,
         PhoneNumber = cinemaUserDTO.PhoneNumber,
         RoleName = cinemaUserDTO.RoleName,
     });
 }
Exemple #6
0
        public int AddUser(CinemaUserDTO registerDTO)
        {
            CinemaUser newUser = new CinemaUser {
                FirstName   = registerDTO.FirstName,
                LastName    = registerDTO.LastName,
                BirthDay    = registerDTO.BirthDay,
                Email       = registerDTO.Email,
                PhoneNumber = registerDTO.PhoneNumber,
                Password    = registerDTO.Password
            };

            _cinemaDbContext.Users.Add(newUser);
            _cinemaDbContext.SaveChanges();
            return(newUser.UserId);
        }
Exemple #7
0
        public bool EditUser(CinemaUserDTO cinemaUserDTO)
        {
            CinemaUser oldUser = _cinemaDbContext.Users.FirstOrDefault(x => x.UserId == cinemaUserDTO.UserId);

            if (oldUser != null)
            {
                oldUser.FirstName   = cinemaUserDTO.FirstName;
                oldUser.LastName    = cinemaUserDTO.LastName;
                oldUser.Email       = cinemaUserDTO.Email;
                oldUser.PhoneNumber = cinemaUserDTO.PhoneNumber;
                _cinemaDbContext.SaveChanges();
                return(true);
            }
            return(false);
        }
Exemple #8
0
        public Response AddUser(CinemaUserDTO registerDTO, string rePassword)
        {
            if (_userRepository.GetUserByEmail(registerDTO.Email) != null)
            {
                return(new Response {
                    IsCompletedSuccesfuly = false,
                    ResponseMessage = "A user with the same email already exists!"
                });
            }
            if (!registerDTO.Password.Equals(rePassword))
            {
                return(new Response {
                    IsCompletedSuccesfuly = false,
                    ResponseMessage = "Passwords doesn't match!"
                });
            }
            int newUserId = _userRepository.AddUser(registerDTO);

            _userRepository.AddUserToRole(newUserId, _userRepository.GetRoleIdByName("User"));
            return(new Response {
                IsCompletedSuccesfuly = true,
                ResponseMessage = "User added succesfuly!"
            });
        }
Exemple #9
0
        public string GetFullName(int id)
        {
            CinemaUserDTO userDTO = _userRepository.GetUserById(id);

            return($"{userDTO.FirstName} ");
        }
 public void EditUser(CinemaUserDTO cinemaUserDTO)
 {
     _userLogic.EditUser(cinemaUserDTO);
 }