Пример #1
0
        public UserAuthenticationInfoViewModel Execute()
        {
            Domain.Users.Authentication.User domainUser = this.userRepository.GetByCredentials(this.UserLoginInfo.Email, this.UserLoginInfo.Password);

            if (domainUser.IsBanned)
            {
                throw new UserIsBannedException();
            }

            if (domainUser == null)
            {
                throw new UserNotFoundException();
            }

            var userViewModel = new UserAuthenticationInfoViewModel
            {
                Name  = domainUser.FirstName,
                Email = this.UserLoginInfo.Email,
                Role  = domainUser.Role.ToString()
            };

            userViewModel.CreateToken(this.appSettings.Secret);

            return(userViewModel);
        }
Пример #2
0
        public UserAuthenticationInfoViewModel Execute()
        {
            User user = Mapper.Map <User>(this.CheckinModel);

            user.Role     = Roles.User;
            user.IsBanned = false;

            try
            {
                this.userRepository.Create(user);
            }
            catch (MongoWriteException ex)
            {
                throw new DuplicateLoginException($"User with login {user.Email} already exist.");
            }

            var userViewModel = new UserAuthenticationInfoViewModel
            {
                Name  = user.FirstName,
                Email = user.Email,
                Role  = user.Role.ToString()
            };

            userViewModel.CreateToken(this.appSettings.Secret);

            return(userViewModel);
        }