Esempio n. 1
0
        public void ActivityLogInsert(UserActivityLogModel activityModel)
        {
            APSEntities dbContext       = new APSEntities();
            var         objUserActivity = new APS_USER_ACT_LOG
            {
                USER_NAME    = activityModel.User_Name,
                USER_ACT_LOG = activityModel.User_Act_Log,
                CREATED_BY   = activityModel.CreatedBy,
                CREATED_TIME = activityModel.CreatedTime
            };

            dbContext.APS_USER_ACT_LOG.Add(objUserActivity);
            dbContext.SaveChanges();
        }
Esempio n. 2
0
 public void ActivityLog(UserActivityLogModel userActivity)
 {
     try
     {
         using (ActivityLoggingRepository repo = new ActivityLoggingRepository())
         {
             repo.ActivityLogInsert(userActivity);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
        public UserModel ChangePassword(ChangePasswordModel model)
        {
            ActivityLoggingComponent activityLog = new ActivityLoggingComponent();
            UserModel authModel = new UserModel();

            authModel.UserName = model.UserName;
            if (IsUserLoginFirstTime(authModel))
            {
                //first time login create new user with password
                UserModel userModel = new UserModel();
                userModel.UserName              = model.UserName;
                userModel.UserPassword          = model.UserPassword;
                userModel.SecretQuestionID      = model.PasswordQuestionID;
                userModel.SecretQuestionAnswer  = model.PasswordQuesAnswer;
                userModel.IsDeleted             = false;
                userModel.LoginFailAttemptCount = 0;
                userModel.CreatedBy             = model.CreatedBy;
                userModel.LastUpdatedBy         = model.LastUpdatedBy;
                return(CreateNewUser(userModel));
            }
            else
            {
                //change the user password
                using (AuthenticationRepository repo = new AuthenticationRepository())
                {
                    string         cryptoKey     = ConfigurationManager.AppSettings.Get("APSEncryptionKey").ToString();
                    ICryptoLibrary cryptLib      = new CryptoLibrary();
                    string         encrypted_pwd = cryptLib.Encrypt(model.UserPassword, cryptoKey);
                    model.UserPassword = encrypted_pwd;
                    var changePassowrd = repo.ChangeUserPassword(model);
                    if (changePassowrd.UserName != string.Empty)
                    {
                        UserActivityLogModel activityModel = new UserActivityLogModel
                        {
                            User_Name    = changePassowrd.UserName,
                            User_Act_Log = "Change password is successful. Activated User Name is: " + changePassowrd.UserName + ".",
                            CreatedBy    = changePassowrd.UserName,
                            CreatedTime  = DateTime.Now
                        };
                        activityLog.ActivityLog(activityModel);
                    }
                    return(changePassowrd);
                }
            }
        }
        /// <summary>
        /// Prepare paged user activity log list model
        /// </summary>
        /// <param name="searchModel">User activity log search model</param>
        /// <param name="user">User</param>
        /// <returns>User activity log list model</returns>
        public virtual UserActivityLogListModel PrepareUserActivityLogListModel(UserActivityLogSearchModel searchModel, User user)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            //get user activity log
            var activityLog = _userActivityService.GetAllActivities(userId: user.Id,
                                                                    pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new UserActivityLogListModel
            {
                Data = activityLog.Select(logItem =>
                {
                    //fill in model values from the entity
                    var userActivityLogModel = new UserActivityLogModel
                    {
                        Id = logItem.Id,
                        ActivityLogTypeName = logItem.ActivityLogType.Name,
                        Comment             = logItem.Comment,
                        IpAddress           = logItem.IpAddress
                    };

                    //convert dates to the user time
                    userActivityLogModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc);

                    return(userActivityLogModel);
                }),
                Total = activityLog.TotalCount
            };

            return(model);
        }
Esempio n. 5
0
        public UserModel CreateNewUser(UserModel model)
        {
            ActivityLoggingComponent activityLog = new ActivityLoggingComponent();
            string cryptoKey = ConfigurationManager.AppSettings.Get("APSEncryptionKey").ToString();

            if (!string.IsNullOrEmpty(cryptoKey))
            {
                ICryptoLibrary cryptLib      = new CryptoLibrary();
                string         encrypted_pwd = cryptLib.Encrypt(model.UserPassword, cryptoKey);
                model.UserPassword = encrypted_pwd;
                using (AuthenticationRepository repo = new AuthenticationRepository())
                {
                    var userCreation = repo.CreateNewUser(model);
                    if (userCreation.UserID > 0)
                    {
                        UserActivityLogModel activityModel = new UserActivityLogModel
                        {
                            User_Name    = userCreation.UserName,
                            User_Act_Log = "User creation successful. Newly created User Name is: " + userCreation.UserName + ".",
                            CreatedBy    = userCreation.CreatedBy,
                            CreatedTime  = DateTime.Now
                        };
                        activityLog.ActivityLog(activityModel);
                    }
                    return(userCreation);
                }
            }
            else
            {
                UserActivityLogModel activityModel = new UserActivityLogModel
                {
                    User_Name    = model.UserName,
                    User_Act_Log = "Error occurred! User creation was unsuccessful for : " + model.UserName + ".",
                    CreatedBy    = model.CreatedBy,
                    CreatedTime  = DateTime.Now
                };
                activityLog.ActivityLog(activityModel);
                throw new Exception();
            }
        }
Esempio n. 6
0
        public ForgetPasswordModel ForgetPassword(ForgetPasswordModel model)
        {
            ActivityLoggingComponent activityLog = new ActivityLoggingComponent();
            string cryptoKey    = ConfigurationManager.AppSettings.Get("APSEncryptionKey").ToString();
            string tempPassword = ConfigurationManager.AppSettings.Get("ResetTempPassword").ToString();

            if (!string.IsNullOrEmpty(cryptoKey))
            {
                ICryptoLibrary cryptLib = new CryptoLibrary();
                using (AuthenticationRepository repo = new AuthenticationRepository())
                {
                    SendEmailRequest emailRequest = new SendEmailRequest();
                    UserModel        userModel    = new UserModel();
                    userModel.UserName = model.UserName;
                    userModel          = repo.GetUserDetails(userModel);
                    if (userModel != null)
                    {
                        if (userModel.PasswordChangeFailAttemptCount <= 3)
                        {
                            if (model.PasswordQuestionID == userModel.SecretQuestionID && model.PasswordQuesAnswer == userModel.SecretQuestionAnswer)
                            {
                                // Reset the password
                                string encrypted_pwd = cryptLib.Encrypt(tempPassword, cryptoKey);
                                model.UserPassword = encrypted_pwd;
                                model.PasswordChangeFailAttempt = 0;
                                model.IsSuccess     = true;
                                model.LastUpdatedBy = model.UserName;
                                var resetModel = repo.ResetPassword(model);
                                //Then send email or sms the password to the user
                                if (!string.IsNullOrEmpty(model.Email))
                                {
                                    BuildAndSendEmailRequest(emailRequest, model.Email, "APS - Reset Password", "Your password has been changed. New password is: " + tempPassword + "Please Change the password after login using the temporary password. Thank You.");
                                }
                                else if (!string.IsNullOrEmpty(model.MobileNumber))
                                {
                                    // send SMS
                                }
                                if (!string.IsNullOrEmpty(model.UserName))
                                {
                                    UserActivityLogModel activityModel = new UserActivityLogModel
                                    {
                                        User_Name    = model.UserName,
                                        User_Act_Log = "Reset password is successful. Activated User Name is: " + model.UserName + ".",
                                        CreatedBy    = model.UserName,
                                        CreatedTime  = DateTime.Now
                                    };
                                    activityLog.ActivityLog(activityModel);
                                }
                                return(resetModel);
                            }
                            else
                            {
                                //Update the PasswordChagneFailAttempt count
                                if (userModel.PasswordChangeFailAttemptCount != 0)
                                {
                                    model.PasswordChangeFailAttempt = userModel.PasswordChangeFailAttemptCount + 1;
                                }
                                else
                                {
                                    model.PasswordChangeFailAttempt = 1;
                                }
                                model.IsSuccess     = false;
                                model.LastUpdatedBy = model.UserName;
                                return(repo.UpdateChangePasswordFailedCount(model));
                            }
                        }
                        else
                        {
                            if (userModel.DOBFailAttemptCount <= 3)
                            {
                                UserInfoModel userInfoModel = new UserInfoModel();
                                userInfoModel.UserName = model.UserName;
                                userInfoModel          = repo.GetUserInfoDetails(userInfoModel);
                                if (userInfoModel != null)
                                {
                                    string dateOfBirth = userInfoModel.UserDateOfBirth;
                                    if (dateOfBirth == model.DateOfBirth)
                                    {
                                        string encrypted_pwd = cryptLib.Encrypt(tempPassword, cryptoKey);
                                        model.UserPassword           = encrypted_pwd;
                                        model.DateOfBirthFailAttempt = 0;
                                        model.IsSuccess                 = true;
                                        model.LastUpdatedBy             = model.UserName;
                                        model.PasswordChangeFailAttempt = userModel.PasswordChangeFailAttemptCount;
                                        var resetModel = repo.ResetPassword(model);
                                        //Then send email or sms the password to the user
                                        if (!string.IsNullOrEmpty(model.Email))
                                        {
                                            BuildAndSendEmailRequest(emailRequest, model.Email, "APS - Reset Password", "Your password has been changed. New password is: " + tempPassword + " Please Change the password after login using the temporary password. Thank You.");
                                        }
                                        else if (!string.IsNullOrEmpty(model.MobileNumber))
                                        {
                                            // send SMS
                                        }
                                        if (!string.IsNullOrEmpty(model.UserName))
                                        {
                                            UserActivityLogModel activityModel = new UserActivityLogModel
                                            {
                                                User_Name    = model.UserName,
                                                User_Act_Log = "Reset password is successful using Date of birth option. Activated User Name is: " + model.UserName + ".",
                                                CreatedBy    = model.UserName,
                                                CreatedTime  = DateTime.Now
                                            };
                                            activityLog.ActivityLog(activityModel);
                                        }
                                        return(resetModel);
                                    }
                                    else
                                    {
                                        //Update the PasswordChagneFailAttempt count
                                        if (userModel.DOBFailAttemptCount != 0)
                                        {
                                            model.DateOfBirthFailAttempt = userModel.DOBFailAttemptCount + 1;
                                        }
                                        else
                                        {
                                            model.DateOfBirthFailAttempt = 1;
                                        }
                                        model.IsSuccess                 = false;
                                        model.LastUpdatedBy             = model.UserName;
                                        model.PasswordChangeFailAttempt = userModel.PasswordChangeFailAttemptCount;
                                        return(repo.UpdateDateOfBirthFailCount(model));
                                    }
                                }
                                else
                                {
                                    model.IsSuccess = false;
                                    return(model);
                                }
                            }
                            else
                            {
                                //Contact case officer - Exceeded all the possible way
                                model.IsSuccess = false;
                                return(model);
                            }
                        }
                    }
                    model.IsSuccess = false;
                    return(model);
                }
            }
            else
            {
                throw new Exception();
            }
        }