Esempio n. 1
0
        /// <summary>
        /// Gets the Error related to the errorCode.
        /// Throws an exception if the error code doesn't exist
        /// </summary>
        /// <param name="errorCode">The code for the error to retrieve</param>
        /// <returns>The error instance</returns>
        public PCHIError GetError(ErrorCodes errorCode)
        {
            PCHIError err = this.context.ErrorsMessages.Where(e => e.ErrorCode == errorCode).SingleOrDefault();

            if (err == null)
            {
                err = this.context.ErrorsMessages.Where(e => e.ErrorCode == ErrorCodes.ERROR_DOES_NOT_EXIST).Single();
            }

            return(err);
        }
Esempio n. 2
0
        /// <summary>
        /// Logs the user in
        /// If Two factor authentication is required the authentication code for that is automatically send to the user
        /// </summary>
        /// <param name="userName">The username of the user</param>
        /// <param name="password">The password of the user</param>
        /// <returns>An operation indicating success with the Data variable indicating if Two factor authentication is required (true) or not (false)</returns>
        public OperationResultAsBool Login(string userName, string password)
        {
            Logger.Audit(new Audit(Model.Security.Actions.LOGIN_STARTED, AuditEventType.READ, typeof(User), "UserName", userName));
            LoginResult result = WcfUserSessionSecurity.Login(userName, password);

            if (result == LoginResult.Success)
            {
                User u = this.handler.UserManager.FindByName(userName);
                if (u.TwoFactorEnabled && u.TwoFactorAuthenticationProvider != null && this.handler.UserManager.TwoFactorProviders.ContainsKey(u.TwoFactorAuthenticationProvider))
                {
                    string token = this.handler.UserManager.GenerateTwoFactorToken(u.Id, u.TwoFactorAuthenticationProvider);
                    this.handler.UserManager.NotifyTwoFactorToken(u.Id, u.TwoFactorAuthenticationProvider, token);
                    return(new OperationResultAsBool(null, true));
                }
                else
                {
                    Logger.Audit(new Audit(Model.Security.Actions.LOGIN_COMPLETED, AuditEventType.READ, typeof(User), "UserName", userName));
                }
            }
            else
            {
                Logger.Audit(new Audit(Model.Security.Actions.LOGIN_COMPLETED, AuditEventType.READ, typeof(User), "UserName", userName, false));
            }

            PCHIError err = null;

            if (result == LoginResult.Failed)
            {
                err = this.handler.MessageManager.GetError(ErrorCodes.LOGIN_FAILED);
            }
            if (result == LoginResult.UserIsLockedOut)
            {
                err = this.handler.MessageManager.GetError(ErrorCodes.USER_IS_LOCKEDOUT);
            }
            if (result == LoginResult.RegistrationNotCompleted)
            {
                err = this.handler.MessageManager.GetError(ErrorCodes.REGISTRATION_NOT_COMPLETED);
            }
            return(new OperationResultAsBool(err, false));
        }