Ejemplo n.º 1
0
 public UserService()
 {
     UserActionService = new UserActionService();
     UserRepository    = new UserRepository();
     AMapper           = new AMapper();
     HashHelper        = new HashHelper(StaticSalt.Salt);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// get UserLoginDTO by username and password
        /// </summary>
        /// <param name="userLogInDTO"></param>
        /// <returns></returns>
        public async Task <UserGetDetailDTO> LogIn(UserLogInDTO userLogInDTO)
        {
            // find users by UserName
            // delete after making ValidationService
            User userEntity = await UserRepository.GetByUserName(userLogInDTO.UserName);

            var userGetDetailDTO = AMapper.Mapper.Map <User, UserGetDetailDTO>(userEntity);

            // add record about signing in the user
            var userAction = new UserActionCreateDTO(userGetDetailDTO.UserID, UserActionType.LogIn);
            await UserActionService.InsertUserActionToDB(userAction);

            return(userGetDetailDTO);
        }
Ejemplo n.º 3
0
        public async Task <int> SignUp(UserCreateDTO user)
        {
            string dynamicSalt    = HashHelper.GetDynamicSalt(user.UserName);
            string hashedPassword = HashHelper.GetPasswordHash(user.Password, dynamicSalt);

            // Map, add fields to customer entity
            User userEntity = AMapper.Mapper.Map <UserCreateDTO, User>(user);

            userEntity.DynamicSalt    = dynamicSalt;
            userEntity.HashedPassword = hashedPassword;

            // Insert the user into the database
            int newUserID = await UserRepository.Insert(userEntity);

            // add record about registration of the user
            var userAction = new UserActionCreateDTO(newUserID, UserActionType.SignUp);
            await UserActionService.InsertUserActionToDB(userAction);

            return(newUserID);
        }
Ejemplo n.º 4
0
        public async Task UpdateUser(UserUpdateDTO user)
        {
            // Map, add fields to customer entity
            User userEntity = AMapper.Mapper.Map <UserUpdateDTO, User>(user);

            var outdatedUser = await UserRepository.GetById(user.UserID);

            if (user.Password == null || user.Password.Length < 1)
            {
                userEntity.HashedPassword = outdatedUser.HashedPassword;
            }
            else
            {
                string hashedPassword = HashHelper.GetPasswordHash(user.Password, outdatedUser.DynamicSalt);
                userEntity.HashedPassword = hashedPassword;
            }

            // Update the customer in the database
            await UserRepository.Update(userEntity);

            // add record about editing of the user
            var userAction = new UserActionCreateDTO(userEntity.UserID, UserActionType.Edit);
            await UserActionService.InsertUserActionToDB(userAction);
        }
Ejemplo n.º 5
0
 public async Task LogOut(int userID)
 {
     var userAction = new UserActionCreateDTO(userID, UserActionType.LogOut);
     await UserActionService.InsertUserActionToDB(userAction);
 }