Пример #1
0
        public void ProcessRequest(HttpContext context)
        {
            string result = null;

            try
            {
                string username;

                if (context.HasParam(SiteParameters.USER_NAME))
                    username = context.Param(SiteParameters.USER_NAME);
                else
                {
                    string email = context.Param(SiteParameters.EMAIL);
                    var user = UserManagementService.FindUserWithEmail(email);
                    username = user.AliasName;
                }

                string password = context.Param(SiteParameters.PASSWORD);

                var lt = SessionUtil.Login(username, password);
                result = JSONHelper.Serialize<LoginToken>(lt);
            }
            catch (UserManagementServiceException umse)
            {
                ExceptionHelper.Code exceptionCode = ExceptionHelper.Code.UnexpectedException;
                string message = umse.Message;

                switch (umse.Code)
                {
                    case UserManagementServiceException.ErrorCode.UnexpectedError:
                        break;
                    case UserManagementServiceException.ErrorCode.ObjectNotFound:
                        exceptionCode = ExceptionHelper.Code.InvalidLogin;
                        break;
                    case UserManagementServiceException.ErrorCode.InvalidOperationOnResource:
                        exceptionCode = ExceptionHelper.Code.InvalidOperation;
                        break;
                    case UserManagementServiceException.ErrorCode.AccessDenied:
                        exceptionCode = ExceptionHelper.Code.AccessDenied;
                        break;
                    case UserManagementServiceException.ErrorCode.CouldNotConnectToDatabase:
                        message = "Could not connect to the database. " + message;
                        break;
                    default:
                        message = "Unknown ErrorCode: " + umse.Code + ". Message: " + message;
                        break;
                }

                result = JSONHelper.Serialize(ExceptionHelper.Handle(umse, exceptionCode, message, log));
            }
            catch (Exception e)
            {
                result = JSONHelper.Serialize(ExceptionHelper.Handle(e, log));
            }
            finally
            {
                context.Response.ContentType = MediaTypeNames.Text.Plain;
                context.Response.Write(result);
            }
        }
Пример #2
0
        public void ProcessRequest(HttpContext context)
        {
            string result = null;

            try
            {
                SiteResponse response;

                if (context.HasParam(SiteParameters.OPERATION)
                        && context.Param<SiteOperation>(SiteParameters.OPERATION) == SiteOperation.ChangePassword)
                    response = ChangePassword(context);
                else
                    response = _ResetPassword(context);

                result = JSONHelper.Serialize<SiteResponse>(response);
            }
            catch (UserManagementServiceException umse)
            {
                ExceptionHelper.Code exceptionCode = ExceptionHelper.Code.UnexpectedException;
                string message = umse.Message;

                switch (umse.Code)
                {
                    case UserManagementServiceException.ErrorCode.UnexpectedError:
                        break;
                    case UserManagementServiceException.ErrorCode.ObjectNotFound:
                        exceptionCode = ExceptionHelper.Code.InvalidLogin;
                        break;
                    case UserManagementServiceException.ErrorCode.InvalidOperationOnResource:
                        exceptionCode = ExceptionHelper.Code.InvalidOperation;
                        break;
                    case UserManagementServiceException.ErrorCode.AccessDenied:
                        exceptionCode = ExceptionHelper.Code.AccessDenied;
                        break;
                    case UserManagementServiceException.ErrorCode.CouldNotConnectToDatabase:
                        message = "Could not connect to the database. " + message;
                        break;
                    default:
                        message = "Unknown ErrorCode: " + umse.Code + ". Message: " + message;
                        break;
                }

                result = JSONHelper.Serialize(ExceptionHelper.Handle(umse, exceptionCode, message, log));
            }
            catch (Exception e)
            {
                result = JSONHelper.Serialize(ExceptionHelper.Handle(e, log));
            }
            finally
            {
                context.Response.ContentType = MediaTypeNames.Text.Plain;
                context.Response.Write(result);
            }
        }
Пример #3
0
        private static SiteResponse _ResetPassword(HttpContext context)
        {
            string email = string.Empty;
            string username = string.Empty;

            if (context.HasParam(SiteParameters.EMAIL))
                email = context.Param(SiteParameters.EMAIL);

            if (context.HasParam(SiteParameters.USER_NAME))
                username = context.Param(SiteParameters.USER_NAME);

            SessionUtil.ResetPassword(username, email);

            if (log.IsInfoEnabled)
                log.Info("PasswordReset status: success");

            return new SiteResponse()
            {
                response = "Please check email for new password.",
                status = SiteResponse.Status.Success,
                syncKey = "aSyncKey"
            };
        }