예제 #1
0
파일: UserVM.cs 프로젝트: anshox/SyncReader
 public UserVM(IClientAuthorizationProvider model, DocumentLibraryVM libraryVM)
 {
     this.libraryVM = libraryVM;
     this.model = model;
     this.model.LoggedIn += OnLoggedStateChanged;
     this.model.LoggedOut += OnLoggedStateChanged;
     this.loginCommand = new RelayCommand(this.Login);
     this.logoutCommand = new RelayCommand(this.Logout);
 }
예제 #2
0
 public LoginWindow(IClientAuthorizationProvider authProvider)
 {
     this.InitializeComponent();
     this.authProvider = authProvider;
     this.loginViewModel = new LoginViewModel(new UserModel(), this.authProvider);
     this.DataContext = this.loginViewModel;
     this.AuthorizationProvider.LoggedIn += () => this.Close();
     this.Show();
 }
예제 #3
0
        public SynchronizationModule(IFilesProvider filesProvider, IDocumentApiProvider documentApiProvider, IClientAuthorizationProvider authorizationProvider)
        {
            this.filesProvider = filesProvider;
            this.documentApiProvider = documentApiProvider;
            this.authorizationProvider = authorizationProvider;

            authorizationProvider.LoggedIn += AuthorizationProvider_LoggedIn;
            authorizationProvider.LoggedOut += AuthorizationProvider_LoggedOut;
            filesProvider.FileAdded += FilesProvider_FileAdded;
            filesProvider.FileRemoved += FilesProvider_FileRemoved;

            this.metadata = filesProvider.Metadata;
        }
예제 #4
0
 public LoginViewModel(UserModel userModel, IClientAuthorizationProvider authorizationProvider)
 {
     this.userModel = userModel;
     this.authorizationProvider = authorizationProvider;
     this.loginCommand = new RelayCommand(this.LoginMethod, param => this.loginCanExecute);
 }
예제 #5
0
        public RegisterViewModel(UserModel userModel, IClientAuthorizationProvider authorizationProvider)
        {
            this.userModel = userModel;
            this.authorizationProvider = authorizationProvider;
            this.registerCommand = new RelayCommand(this.RegisterMethod, param => this.registerCanExecute);

            Regex usernameAllowedSymbolsRegex = new Regex("^[a-z0-9_]*$", RegexOptions.Compiled);
            Regex usernameStartsWithRegex = new Regex("^[a-z]", RegexOptions.Compiled);
            Regex passwordTwoUppercaseLettersRegex = new Regex("^.*([A-Z].*){2,}$", RegexOptions.Compiled);
            Regex passwordTwoLowercaseLettersRegex = new Regex("^.*([a-z].*){2,}$", RegexOptions.Compiled);
            Regex passwordTwoCyphersRegex = new Regex("^.*([0-9].*){2,}$", RegexOptions.Compiled);

            this.AddValidationProperties(new List<ValidationProperty>
                {
                    new ValidationProperty
                    {
                        PropertyName = "UserName",
                        RuleSet = new List<ValidationRule>
                        {
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return this.UserName != null &&
                                        this.UserName.Length > 2 &&
                                        this.UserName.Length < 16;
                                },
                                ErrorMessage = "The username length must be 3-15 characters long."
                            },
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return string.IsNullOrEmpty(this.UserName) ||
                                        usernameAllowedSymbolsRegex.IsMatch(this.UserName);
                                },
                                ErrorMessage = "Allowed characters for the username are lowercase letters, cyphers, and the underscore symbol."
                            },
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return string.IsNullOrEmpty(this.UserName) ||
                                        usernameStartsWithRegex.IsMatch(this.UserName);
                                },
                                ErrorMessage = "The username have to start with lowercase letter."
                            },
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return !string.IsNullOrEmpty(this.UserName) &&
                                        this.UserName.Length > 2 &&
                                        this.authorizationProvider.IsUsernameAvailable(this.UserName);
                                },
                                ErrorMessage = "This username is already used."
                            }
                        }
                    },
                    new ValidationProperty
                    {
                        PropertyName = "Password",
                        RuleSet = new List<ValidationRule>
                        {
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return this.Password != null &&
                                        this.Password.Length > 7;
                                },
                                ErrorMessage = "The password must be at least 8 characters long."
                            },
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return string.IsNullOrEmpty(this.Password) ||
                                        passwordTwoUppercaseLettersRegex.IsMatch(this.Password);
                                },
                                ErrorMessage = "The password must have at least two uppercase letters."
                            },
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return string.IsNullOrEmpty(this.Password) ||
                                        passwordTwoLowercaseLettersRegex.IsMatch(this.Password);
                                },
                                ErrorMessage = "The password must have at least two lowercase letters."
                            },
                            new ValidationRule
                            {
                                Rule = () =>
                                {
                                    return string.IsNullOrEmpty(this.Password) ||
                                        passwordTwoCyphersRegex.IsMatch(this.Password);
                                },
                                ErrorMessage = "The password must have at least two cyphers."
                            }
                        }
                    },
                    new ValidationProperty
                    {
                        PropertyName = "ConfirmPassword",
                        RuleSet = new List<ValidationRule>
                        {
                            new ValidationRule
                            {
                                Rule = () => !string.IsNullOrEmpty(this.ConfirmPassword),
                                ErrorMessage = string.Empty
                            },
                            new ValidationRule
                            {
                                Rule = () => this.Password == this.ConfirmPassword,
                                ErrorMessage = "Passwords does not match."
                            }
                        }
                    }
                });
            this.AddPropertySubscriber("Password", b => this.PasswordHasErrors = b);
            this.AddPropertySubscriber("ConfirmPassword", b => this.ConfirmPasswordHasErrors = b);
        }