Beispiel #1
0
 public SessionDto CheckSession(string securityToken)
 {
     using (var _sessionServices = new SessionServices())
     {
         var minutes = Convert.ToInt32($"{configuration["MinutesToExpireSession"]}") * -1;
         _sessionServices.DeleteExpiredSessions(DateTime.Now.AddMinutes(minutes));
         return(_sessionServices.Read(securityToken));
     }
 }
 public void Logout(string securityToken)
 {
     try
     {
         using (var _sessionServices = new SessionServices())
             _sessionServices.Delete(securityToken);
     }
     catch (Exception e)
     {
         throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e);
     }
 }
        public string Register(UserRegistrationDto user)
        {
            try
            {
                if (user.Username.Length < 6)
                {
                    throw new FileSharingException(FileSharingException.USERNAME_FIELD_LENGTH, "Username must have 6 characters at least");
                }
                if (user.Password.Length < 6)
                {
                    throw new FileSharingException(FileSharingException.PASSWORD_FIELD_LENGTH, "Password must have 6 characters at least");
                }
                if (user.Password != user.ConfirmPassword)
                {
                    throw new FileSharingException(FileSharingException.PASSWORD_NOT_MATCHING, "The password and confirmation password do not match");
                }
                var userDom = Mapper.Map <User>(user);
                ValidateUser(userDom);
                if (_dao.ReadByLogin(userDom.Login) != null)
                {
                    throw new FileSharingException(FileSharingException.LOGIN_ALREADY_IN_USE, "Login already in use");
                }

                userDom.Password = EncryptPassword(user.Password);
                userDom          = _dao.Create(userDom);

                Audit(userDom.Id, userDom.Id.ToString(), typeof(User).Name, ActionDto.Create, "User registered: " + userDom);

                using (var _sessionServices = new SessionServices())
                    return(_sessionServices.Create(userDom.Id));
            }
            catch (FileSharingException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e);
            }
        }
 public string Login(UserLoginDto login)
 {
     try
     {
         var userDom = _dao.ReadByLogin(login.Username);
         if (userDom == null || userDom.Password != EncryptPassword(login.Password))
         {
             throw new FileSharingException(FileSharingException.INVALID_CREDENTIALS,
                                            "The username or the password is not valid");
         }
         using (var _sessionServices = new SessionServices())
             return(_sessionServices.Create(userDom.Id));
     }
     catch (FileSharingException)
     {
         throw;
     }
     catch (Exception e)
     {
         throw new FileSharingException(FileSharingException.ERROR_FILESHARING_SERVER, e.Message, e);
     }
 }