Exemplo n.º 1
0
        public override void Process(ApiServer server)
        {
            if (server.AssertServerSetup(this) || server.AssertAccountNotNull() || server.AssertUserOnline() || server.AssertEmailSet())
            {
                return;
            }
            if (!EmailEssentials.IsValid(server.Account.AccountInfo.Email))
            {
                ApiError.Throw(ApiErrorCode.InvalidEmailAddress, server, "Email address is invalid.");
                return;
            }
            server.Account.AuthenticationCode = SecurityManager.GenerateSecurityCode();
            server.Account.AuthenticationId   = ApiRequestId.ConfirmPasswordChange;
            server.Account.AuthenticationTime = DatabaseEssentials.GetTimeStamp();
            server.Account.Password           = SecurityManager.ScryptHash(Password);
            string       name         = string.IsNullOrEmpty(server.Account.AccountInfo.Name) ? "user" : server.Account.AccountInfo.Name;
            EmailManager emailManager = EmailManager.Create(Subject.ChangePassword, server.Account.AccountInfo.Email, name, server.Account.AuthenticationCode);
            bool         success      = emailManager.Send();

            if (!success)
            {
                ApiError.Throw(ApiErrorCode.InternalServerError, server, "Failed to send confirmation email.");
                return;
            }
            GenericSuccessResponse apiResponse           = new GenericSuccessResponse(ResponseId.PasswordChange, true);
            SerializedApiResponse  serializedApiResponse = SerializedApiResponse.Create(apiResponse);
            string json = serializedApiResponse.Serialize();

            server.Send(json);
            server.UnitTesting.MethodSuccess = true;
        }
Exemplo n.º 2
0
        public override void Process(ApiServer server)
        {
            if (server.AssertServerSetup(this) || server.AssertAccountNotNull() || server.AssertUserOnline())
            {
                return;
            }
            using DatabaseManager databaseManager = new DatabaseManager(server);
            string id = databaseManager.UserIdToId(UserId, out bool success);

            if (!success)
            {
                return;
            }
            Account account = databaseManager.GetAccount(id, out success);

            if (!success)
            {
                return;
            }
            account.AccountInfo.Radius = -1;
            GetAccountInfoResponse response = new GetAccountInfoResponse(ResponseId.GetAccountInfo, account.AccountInfo);
            SerializedApiResponse  serializedApiResponse = SerializedApiResponse.Create(response);
            string json = serializedApiResponse.Serialize();

            server.Send(json);
            server.UnitTesting.MethodSuccess = true;
        }