Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace SpaceTakeover
- {
- public class LoginData : ModelBase
- {
- public override string this[string columnName]
- {
- get { return null; }
- }
- private string username = String.Empty;
- public string Username
- {
- get { return username; }
- set { username = value; NotifyOnPropertyChanged("Username"); }
- }
- private string password = String.Empty;
- public string Password
- {
- get { return password; }
- set { password = value; NotifyOnPropertyChanged("Password"); }
- }
- }
- public class RegistrationData : ModelBase
- {
- public override string this[string columnName]
- {
- get
- {
- string errorString = null;
- if (columnName == "Username")
- {
- if (String.IsNullOrEmpty(Username) || Username.Length < 3)
- {
- errorString = "Username must be at least 3 characters.";
- }
- }
- if (columnName == "ReEnterPassword")
- {
- if (ReEnterPassword != Password)
- {
- errorString = "Passwords do not match.";
- }
- }
- if (columnName == "Email")
- {
- if (!System.Text.RegularExpressions.Regex.IsMatch(Email, @"(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})"))//If email is syntatically valid
- {
- errorString = "Email is in an invalid format.";
- }
- }
- return errorString;
- }
- }
- private string username = String.Empty;
- public string Username
- {
- get { return username; }
- set { username = value; NotifyOnPropertyChanged("Username"); }
- }
- private string password = String.Empty;
- public string Password
- {
- get { return password; }
- set { password = value; NotifyOnPropertyChanged("Password"); }
- }
- private string rePassword = String.Empty;
- public string ReEnterPassword
- {
- get { return rePassword; }
- set { rePassword = value; NotifyOnPropertyChanged("ReEnterPassword"); }
- }
- private string betaKey = String.Empty;
- public string BetaKey
- {
- get { return betaKey; }
- set { betaKey = value; NotifyOnPropertyChanged("BetaKey"); }
- }
- private string email = String.Empty;
- public string Email
- {
- get { return email; }
- set { email = value; NotifyOnPropertyChanged("Email"); }
- }
- private bool registerEnabled = true;
- public bool RegisterEnabled
- {
- get { return registerEnabled; }
- set { registerEnabled = value; NotifyOnPropertyChanged("RegisterEnabled"); }
- }
- }
- public class LoginCommand : CommandBase
- {
- private LoginRegisterClient client;
- public LoginCommand()
- {
- client = new LoginRegisterClient();
- Text = "Login";
- }
- public LoginCommand(LoginRegisterClient remoteClient)
- {
- client = remoteClient;
- }
- public override bool CanExecute(object parameter)
- {
- return parameter is TextBlock;
- }
- public override void Execute(object parameter)
- {
- TextBlock errorBlock = parameter as TextBlock;
- client.LoginCompleted += GenerateLoginCompletedDelegate(errorBlock);
- }
- private EventHandler<LoginCompletedEventArgs> GenerateLoginCompletedDelegate(TextBlock errorBlock)
- {
- return (object sender, LoginCompletedEventArgs e) =>
- {
- bool loginSuccess = e.Result;
- if (!loginSuccess)
- {
- errorBlock.Text = "Login Failed.";
- }
- else
- {
- FrameworkElement ctrl = errorBlock;
- while (!((ctrl = ctrl.Parent as FrameworkElement) is PageSwitcher))
- {
- if (ctrl != null)
- {
- PageSwitcher ps = ctrl as PageSwitcher;
- ps.Navigate(new SelectUniversePage());
- }
- }
- }
- };
- }
- }
- public class RegisterCommand : CommandBase
- {
- private LoginRegisterClient client;
- public RegisterCommand()
- {
- client = new LoginRegisterClient();
- Text = "Register";
- }
- public RegisterCommand(LoginRegisterClient remoteClient)
- {
- client = remoteClient;
- }
- public override bool CanExecute(object parameter)
- {
- return parameter is TextBlock;
- }
- public override void Execute(object parameter)
- {
- TextBlock errorBlock = parameter as TextBlock;
- client.RegisterCompleted += GenerateRegistrationCompletedDelegate(errorBlock);
- }
- private EventHandler<RegisterCompletedEventArgs> GenerateRegistrationCompletedDelegate(TextBlock errorBlock)
- {
- return (object sender, RegisterCompletedEventArgs e) =>
- {
- bool loginSuccess = e.Result;
- if (!loginSuccess)
- {
- errorBlock.Text = "Registration Failed.";
- }
- else
- {
- FrameworkElement ctrl = errorBlock;
- while (!((ctrl = ctrl.Parent as FrameworkElement) is PageSwitcher))
- {
- if (ctrl != null)
- {
- PageSwitcher ps = ctrl as PageSwitcher;
- ps.Navigate(new SelectUniversePage());
- }
- }
- }
- };
- }
- }
- public class ViewModelLoginRegister
- {
- private LoginRegisterClient client = new LoginRegisterClient();
- public LoginCommand LoginCmd { get; set; }
- public LoginData LoginInfo { get; set; }
- public RegistrationData RegistrationInfo { get; set; }
- public RegisterCommand RegisterCmd { get; set; }
- public ViewModelLoginRegister()
- {
- LoginInfo = new LoginData();
- RegistrationInfo = new RegistrationData();
- LoginCmd = new LoginCommand(client);
- RegisterCmd = new RegisterCommand(client);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement