internal static void SaveAspUserAsync(common.AspUser saveUser, SaveAspUserCallBack callback)
        {
            Guid callerKey = Guid.NewGuid();
            ApartmentServiceClient proxy = GetProxy(callerKey, callback);

            proxy.SaveAspUserCompleted += new EventHandler <SaveAspUserCompletedEventArgs>(proxy_SaveAspUserCompleted);
            proxy.SaveAspUserAsync(saveUser, callerKey);
        }
        internal static void UnlockAspUserAsync(common.AspUser oldUser, UnlockAspUserCallBack callback)
        {
            Guid callerKey = Guid.NewGuid();

            ApartmentServiceClient proxy = GetProxy(callerKey, callback);

            proxy.UnlockAspUserCompleted += new EventHandler <UnlockAspUserCompletedEventArgs>(proxy_UnlockAspUserCompleted);
            proxy.UnlockAspUserAsync(oldUser, callerKey);
        }
        static void proxy_UnlockAspUserCompleted(object sender, UnlockAspUserCompletedEventArgs e)
        {
            Guid callerKey = (Guid)e.UserState;

            if (_callbacks.ContainsKey(callerKey))
            {
                common.AspUser itemSource = e.Result;
                ((UnlockAspUserCallBack)_callbacks[callerKey]).Invoke(itemSource);

                _callbacks.Remove(callerKey);
            }
        }
        static void proxy_SaveAspUserCompleted(object sender, SaveAspUserCompletedEventArgs e)
        {
            Guid callerKey = (Guid)e.UserState;

            if (_callbacks.ContainsKey(callerKey))
            {
                common.AspUser result = e.Result;
                ((SaveAspUserCallBack)_callbacks[callerKey]).Invoke(result);

                _callbacks.Remove(callerKey);
            }
        }
Beispiel #5
0
        public static AspUser AspUser(System.Data.IDataReader reader)
        {
            AspUser result = null;

            if (null != reader && reader.Read())
            {
                result = new AspUser();
                PopulateAspUser(result, reader);
            }

            return result;
        }
        internal static void UnlockAspUserAsync(AspUser oldUser, UnlockAspUserCallBack callback)
        {
            Guid callerKey = Guid.NewGuid();

            ApartmentServiceClient proxy = GetProxy(callerKey, callback);
            proxy.UnlockAspUserCompleted += new EventHandler<UnlockAspUserCompletedEventArgs>(proxy_UnlockAspUserCompleted);
            proxy.UnlockAspUserAsync(oldUser, callerKey);
        }
 internal static void SaveAspUserAsync(AspUser saveUser, SaveAspUserCallBack callback)
 {
     Guid callerKey = Guid.NewGuid();
     ApartmentServiceClient proxy = GetProxy(callerKey, callback);
     proxy.SaveAspUserCompleted += new EventHandler<SaveAspUserCompletedEventArgs>(proxy_SaveAspUserCompleted);
     proxy.SaveAspUserAsync(saveUser, callerKey);
 }
 public AspUser UnlockAspUser(AspUser oldUser)
 {
     if (oldUser != null)
     {
         MembershipUser memberShipUser = Membership.GetUser(oldUser.UserId);
         memberShipUser.UnlockUser();
         oldUser = GetAspUser(oldUser.UserId);
     }
     return oldUser;
 }
        void SaveAspUserCompleted(AspUser aspUser)
        {
            for (int i = 0; i < _aspUsers.Count; i++)
            {
                if (_aspUsers[i].UserId == aspUser.UserId)
                {
                    if (aspUser.IsSavedQAError)
                    {
                        MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_InputPasswordIncorrect"));
                    }
                    else if (!string.IsNullOrEmpty(aspUser.ErrorMessage))
                    {
                        MessageBox.Show(aspUser.ErrorMessage);
                    }
                    else
                    {
                        _aspUsers[i] = aspUser;
                        SavedAspUser = aspUser;
                        if (SaveUserAccountComplete != null)
                        {
                            SaveUserAccountComplete(this, null);
                        }
                        RebindUserAccountData();
                        if (!string.IsNullOrEmpty(aspUser.NewGenPassword))
                        {
                            txtResetPasswordInfo.Text = string.Format(ResourceHelper.GetReourceValue("UserAccount_NewGenPassword"), aspUser.NewGenPassword);
                            txtResetPasswordInfo.Visibility = System.Windows.Visibility.Visible;
                        }
                        else
                        {
                            txtResetPasswordInfo.Visibility = System.Windows.Visibility.Collapsed;
                        }

                        MessageBox.Show(Globals.UserMessages.RecordsSaved);
                    }

                    break;
                }
            }
            Globals.IsBusy = false;
        }
Beispiel #10
0
        private AspUser GetSaveAspUser(AspUser aspUser)
        {
            aspUser.IsResetPassword = chkResetPassword.IsChecked == true;
            aspUser.IsApproved = chkAccountApproved.IsChecked == true;
            aspUser.Email = txtEmail.Text;
            if (chkChangePasswordQuestionAnswer.IsChecked == true)
            {
                aspUser.PasswordQuestion = txtPasswordQuestion.Text;
                aspUser.PasswordAnswer = txtPasswordAnswer.Text;
                if (string.IsNullOrEmpty(aspUser.PasswordQuestion))
                    aspUser.PasswordQuestion = ResourceHelper.GetReourceValue("UserAccount_DefaultPasswordQuestion");
                if (string.IsNullOrEmpty(aspUser.PasswordAnswer))
                    aspUser.PasswordAnswer = ResourceHelper.GetReourceValue("UserAccount_DefaultPasswordAnswer");
                aspUser.InputPassword = txtInputPassword.Password;
            }
            else
            {
                aspUser.PasswordQuestion = string.Empty;
                aspUser.PasswordAnswer = string.Empty;
            }

            aspUser.ErrorMessage = string.Empty;
            return aspUser;
        }
Beispiel #11
0
        void CreateAspUserCompleted(AspUser aspUser)
        {
            //if (!string.IsNullOrEmpty(aspUser.ErrorMessage))
            //{
            //    Globals.IsBusy = false;
            //    MessageBox.Show(aspUser.ErrorMessage);
            //    return;
            //}
            //_aspUsers.Add(aspUser);
            //SavedAspUser = aspUser;
            //if (SaveUserAccountComplete != null)
            //{
            //    SaveUserAccountComplete(this, null);
            //}
            //Dictionary<Guid, string> userItemSource = uiUsers.ItemsSource as Dictionary<Guid, string>;
            //userItemSource.Add(aspUser.UserId, aspUser.UserName);
            //userItemSource.OrderBy(i => i.Value);
            //uiUsers.ItemsSource = null;
            //uiUsers.ItemsSource = userItemSource;
            //uiUsers.SelectedValue = aspUser.UserId;
            //RebindUserAccountData();
            //Globals.IsBusy = false;
            //MessageBox.Show(Globals.UserMessages.RecordsSaved);

            if (!string.IsNullOrEmpty(aspUser.ErrorMessage))
            {
                Globals.IsBusy = false;
                MessageBox.Show(aspUser.ErrorMessage);
                return;
            }
            _aspUsers.Add(aspUser);
            SavedAspUser = aspUser;
            if (SaveUserAccountComplete != null)
            {
                SaveUserAccountComplete(this, null);
            }
            Dictionary<Guid, string> userItemSource = uiUsers.ItemsSource as Dictionary<Guid, string>;
            userItemSource.Add(aspUser.UserId, aspUser.UserName);
            userItemSource.OrderBy(i => i.Value);
            uiUsers.ItemsSource = null;
            uiUsers.ItemsSource = userItemSource;
            uiUsers.SelectedValue = aspUser.UserId;
            RebindUserAccountData();
            if (Globals.UserLogin.IsUserPortalAdministrator)
            {
                UserRoleAuth uraOrgAdmin = new UserRoleAuth();
                uraOrgAdmin.RoleId = SecurityHelper.OrganisationAdministratorRoleId;
                uraOrgAdmin.WholeOrg = true;
                uraOrgAdmin.UserId = aspUser.UserId;
                uraOrgAdmin.IsChanged = true;
                uraOrgAdmin.CreatedBy = uraOrgAdmin.UpdatedBy = Globals.UserLogin.UserName;

                UserRoleAuth uraSecurityAdmin = new UserRoleAuth();
                uraSecurityAdmin.RoleId = SecurityHelper.SecurityAdminRoleId;
                uraSecurityAdmin.WholeOrg = true;
                uraSecurityAdmin.UserId = aspUser.UserId;
                uraSecurityAdmin.IsChanged = true;
                uraSecurityAdmin.CreatedBy = uraSecurityAdmin.UpdatedBy = Globals.UserLogin.UserName;

                List<UserRoleAuth> saveList = new List<UserRoleAuth>();
                saveList.Add(uraOrgAdmin);
                saveList.Add(uraSecurityAdmin);
                DataServiceHelper.SaveUserRoleAuthAsync(saveList, SaveUserRoleAuthCompleted);
            }
            else
            {
                Globals.IsBusy = false;
                MessageBox.Show(Globals.UserMessages.RecordsSaved);
            }
        }
Beispiel #12
0
        void btnSave_Click(object sender, RoutedEventArgs e)
        {
            if (chkChangePasswordQuestionAnswer.IsChecked == true
                 && (string.IsNullOrEmpty(txtPasswordQuestion.Text) || string.IsNullOrEmpty(txtPasswordAnswer.Text)))
            {
                MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_QuestionPasswordEmpty"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                return;
            }

            if (uiUsers.SelectedValue != null && (Guid)uiUsers.SelectedValue != Guid.Empty)//Means update user
            {
                Guid userId = (Guid)uiUsers.SelectedValue;
                AspUser aspUser = _aspUsers.FirstOrDefault(i => i.UserId == userId);
                if (aspUser != null)
                {
                    Globals.IsBusy = true;
                    aspUser = GetSaveAspUser(aspUser);
                    DataServiceHelper.SaveAspUserAsync(aspUser, SaveAspUserCompleted);
                }
                if (chkChangePasswordQuestionAnswer.IsChecked == true
                    && string.IsNullOrEmpty(txtInputPassword.Password))
                {
                    MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_.InputPasswordEmpty"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                    return;
                }
            }
            else//means create new user
            {
                if (string.IsNullOrEmpty(uiUsers.Text) || string.IsNullOrEmpty(txtPassword.Password))
                {
                    MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_.UserPasswordEmpty"), ResourceHelper.GetReourceValue("Common_ValidationError"), MessageBoxButton.OK);
                    return;
                }
                AspUser newUser = new AspUser();
                newUser.OrganisationId = Globals.UserLogin.UserOrganisationId;
                newUser.UserName = uiUsers.Text;
                newUser.Password = txtPassword.Password;
                newUser = GetSaveAspUser(newUser);
                if (_currentOrgId > 0)
                {
                    newUser.OrganisationId = _currentOrgId;
                }
                if (string.IsNullOrEmpty(newUser.PasswordQuestion))
                    newUser.PasswordQuestion = ResourceHelper.GetReourceValue("UserAccount_DefaultPasswordQuestion");
                if (string.IsNullOrEmpty(newUser.PasswordAnswer))
                    newUser.PasswordAnswer = ResourceHelper.GetReourceValue("UserAccount_DefaultPasswordAnswer");
                Globals.IsBusy = true;
                DataServiceHelper.SaveAspUserAsync(newUser, CreateAspUserCompleted);
            }
        }
 public bool DeleteAspUser(AspUser aspUser, long? employeeId)
 {
     bool userDeleted = Membership.DeleteUser(aspUser.UserName);
     return userDeleted;
 }
 private AspUser ConvertUser(MembershipUser membership)
 {
     AspUser user = new AspUser();
     if (membership == null)
         return null;
     user.UserId = Utilities.ToGuid(membership.ProviderUserKey);
     user.UserName = membership.UserName;
     user.IsApproved = membership.IsApproved;
     user.IsLockedOut = membership.IsLockedOut;
     user.IsOnline = membership.IsOnline;
     user.Comment = membership.Comment;
     user.CreationDate = membership.CreationDate;
     user.Email = membership.Email;
     user.LastActivityDate = membership.LastActivityDate;
     user.LastLockoutDate = membership.LastLockoutDate;
     user.LastLoginDate = membership.LastLoginDate;
     user.LastPasswordChangedDate = membership.LastPasswordChangedDate;
     user.PasswordQuestion = membership.PasswordQuestion;
     user.ProviderName = membership.ProviderName;
     user.ProviderUserKey = membership.ProviderUserKey;
     user.Password = "******";
     return user;
 }
Beispiel #15
0
 void UnlockAspUserCompleted(AspUser aspUser)
 {
     for (int i = 0; i < _aspUsers.Count; i++)
     {
         if (_aspUsers[i].UserId == aspUser.UserId)
         {
             _aspUsers[i] = aspUser;
             RebindUserAccountData();
             MessageBox.Show(ResourceHelper.GetReourceValue("UserAccount_UserUnlocked"));
             break;
         }
     }
     Globals.IsBusy = true;
 }
Beispiel #16
0
        public static void PopulateAspUser(AspUser input, System.Data.IDataReader reader)
        {
            input.ApplicationId = Utilities.ToGuid(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.ApplicationId]);
            input.UserId = Utilities.ToGuid(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.UserId]);
            input.Password = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.Password]);
            input.PasswordFormat = Utilities.ToInt(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.PasswordFormat]);
            input.PasswordSalt = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.PasswordSalt]);
            input.MobilePIN = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.MobilePIN]);
            input.Email = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.Email]);

            input.Email = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.Email]);
            input.LoweredEmail = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.LoweredEmail]);
            input.PasswordQuestion = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.PasswordQuestion]);
            input.PasswordAnswer = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.PasswordAnswer]);
            input.IsApproved = Utilities.ToBool(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.IsApproved]);
            input.IsLockedOut = Utilities.ToBool(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.IsLockedOut]);
            input.CreationDate = Utilities.ToDateTime(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.CreateDate]);
            input.LastLoginDate = Utilities.ToDateTime(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.LastLoginDate]);
            input.LastPasswordChangedDate = Utilities.ToDateTime(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.LastPasswordChangedDate]);
            input.LastLockoutDate = Utilities.ToDateTime(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.LastLockoutDate]);

            input.FailedPasswordAttemptCount = Utilities.ToInt(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.FailedPasswordAttemptCount]);
            input.FailedPasswordAttemptWindowStart = Utilities.ToDateTime(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.FailedPasswordAttemptWindowStart]);
            input.FailedPasswordAnswerAttemptCount = Utilities.ToInt(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.FailedPasswordAnswerAttemptCount]);
            input.FailedPasswordAnswerAttemptWindowStart = Utilities.ToDateTime(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.FailedPasswordAnswerAttemptWindowStart]);
            input.Comment = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.Comment]);
            input.UserName = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.UserName]);
            input.LoweredUserName = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.LoweredUserName]);
            input.MobileAlias = Utilities.ToString(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.MobileAlias]);

            input.IsAnonymous = Utilities.ToBool(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.IsAnonymous]);

            input.OrganisationId = Utilities.ToNInt(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.OrganisationId]);
            input.SiteId = Utilities.ToNInt(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.SiteId]);
            if (reader.ColumnExists(Mimosa.Apartment.Common.AspUser.ColumnNames.MinRoleLevel))
                input.MinRoleLevel = Utilities.ToNInt(reader[Mimosa.Apartment.Common.AspUser.ColumnNames.MinRoleLevel]);
            else
                input.MinRoleLevel = 1000;
        }
        public AspUser SaveAspUser(AspUser saveUser)
        {
            if (saveUser != null)
            {
                MembershipProvider simpleProvider = Membership.Providers["SimpleProvider"];

                if (saveUser.UserId == Guid.Empty) //means this is new user : create user
                {
                    // Insert New Membership Account
                    MembershipCreateStatus status;
                    MembershipUser newUser = Membership.CreateUser(saveUser.UserName, saveUser.Password, saveUser.Email,
                            saveUser.PasswordQuestion, saveUser.PasswordAnswer, saveUser.IsApproved, out status);

                    if (status == MembershipCreateStatus.Success)
                    {
                        Guid newUserId = Utilities.ToGuid(newUser.ProviderUserKey);
                        ApartmentMethods.UpdateAspUserOrganisationId(newUserId, saveUser.OrganisationId);
                        saveUser = GetAspUser(newUserId);
                    }
                    else
                    {
                        switch (status)
                        {
                            case MembershipCreateStatus.DuplicateEmail:
                                saveUser.ErrorMessage = "The e-mail address already exists in the database for the application."; break;
                            case MembershipCreateStatus.DuplicateProviderUserKey:
                                saveUser.ErrorMessage = "The provider user key already exists in the database for the application."; break;
                            case MembershipCreateStatus.DuplicateUserName:
                                saveUser.ErrorMessage = "The user name already exists in the database for the application."; break;
                            case MembershipCreateStatus.InvalidAnswer:
                                saveUser.ErrorMessage = "The password answer is not formatted correctly."; break;
                            case MembershipCreateStatus.InvalidEmail:
                                saveUser.ErrorMessage = "The e-mail address is not formatted correctly."; break;
                            case MembershipCreateStatus.InvalidProviderUserKey:
                                saveUser.ErrorMessage = "The provider user key is of an invalid type or format."; break;
                            case MembershipCreateStatus.InvalidQuestion:
                                saveUser.ErrorMessage = "The password question is not formatted correctly."; break;
                            case MembershipCreateStatus.InvalidUserName:
                                saveUser.ErrorMessage = "The user name was not found in the database."; break;
                            case MembershipCreateStatus.InvalidPassword:
                                saveUser.ErrorMessage = "The password is not formatted correctly."; break;
                            default:
                                saveUser.ErrorMessage = "Fail to create new user";
                                break;

                        }

                    }
                }
                else
                {
                    MembershipUser memberShipUser = Membership.GetUser(saveUser.UserId);
                    int? updateCode = null;
                    if (memberShipUser.UserName != saveUser.UserName)
                    {
                        updateCode = ApartmentMethods.UpdateMembershipUserName(Membership.ApplicationName, memberShipUser.UserName, saveUser.UserName);
                        memberShipUser = Membership.GetUser(saveUser.UserId);
                    }

                    string newGenPassword = string.Empty;
                    bool saveQAerror = false;
                    if (updateCode == null || updateCode == 0)
                    {
                        memberShipUser.Email = saveUser.Email;
                        memberShipUser.IsApproved = saveUser.IsApproved;
                        Membership.UpdateUser(memberShipUser);

                        if (!string.IsNullOrEmpty(saveUser.PasswordQuestion) && !string.IsNullOrEmpty(saveUser.PasswordAnswer))
                        {
                            saveQAerror = !memberShipUser.ChangePasswordQuestionAndAnswer(saveUser.InputPassword, saveUser.PasswordQuestion, saveUser.PasswordAnswer);
                        }

                        if (saveUser.IsResetPassword)
                        {
                            if (simpleProvider != null)
                            {
                                MembershipUser simpleUser = simpleProvider.GetUser(saveUser.UserId, false);
                                if (simpleUser != null)
                                {
                                    if (saveUser.IsResetPassword)
                                    {
                                        newGenPassword = simpleUser.ResetPassword();
                                    }
                                }
                            }
                        }
                    }
                    saveUser = GetAspUser(saveUser.UserId);
                    saveUser.NewGenPassword = newGenPassword;
                    saveUser.IsSavedQAError = saveQAerror;
                }
            }

            return saveUser;
        }