Ejemplo n.º 1
0
        /// <summary> Recovery process -> validate token -> save new password </summary>
        public DataResult <RecoveryRequest> Recovery(string newPassword, string token)
        {
            DataResult <RecoveryRequest> drDefaultResponse = new DataResult <RecoveryRequest>()
            {
                Success = false, ErrorMessage = "Unable to process your recovery request"
            };
            DataResult <RecoveryRequest> drRecoveryRequest = database.GetRecoveryRequest(new RecoveryRequest {
                Token = token
            });

            if (!drRecoveryRequest.Success)
            {
                return(drDefaultResponse);
            }

            RecoveryRequest recoveryRequest = drRecoveryRequest.Data.FirstOrDefault();

            if (recoveryRequest == null)
            {
                return(drDefaultResponse);
            }

            if (DateTime.Compare(recoveryRequest.ExpiryDate, DateTime.Now) > 1)
            {
                return(drDefaultResponse);
            }

            DataResult <User> drUser = database.GetUser(new User {
                Id = recoveryRequest.UserId
            });

            if (!drUser.Success)
            {
                return(drDefaultResponse);
            }

            User user = drUser.Data.FirstOrDefault();

            if (user == null)
            {
                return(drDefaultResponse);
            }

            Validator validator = new Validator();

            user.Password = newPassword;
            string hashedPassword = validator.PasswordHasher(user);

            user.Password = hashedPassword;

            DataResult <User> drUserUpdated = database.UpdateUser(user);

            if (!drUserUpdated.Success)
            {
                return(drDefaultResponse);
            }

            DataResult <RecoveryRequest> drDeleteRecoveryRequest = database.DeleteRecoveryRequest(recoveryRequest);

            return(drDeleteRecoveryRequest);
        }
Ejemplo n.º 2
0
        /// <summary> Store formatted packets </summary>
        public DataResult <PacketFormatted> StorePacketsFormatted(List <PacketFormatted> packets)
        {
            DataResult <PacketFormatted> dr = database.StorePacketsFormatted(packets);

            return(dr);
        }
Ejemplo n.º 3
0
        /// <summary> Store user settings </summary>
        public bool SaveSettings(Settings settings)
        {
            DataResult <Settings> dr = database.StoreSettings(settings);

            return(dr.Success);
        }