Guest User

Untitled

a guest
Mar 13th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. namespace ProEventsApp
  2. {
  3. public class OnSignUpEventArgs : EventArgs
  4. {
  5. public int zID;
  6. public string zUsername;
  7. public string zPassword;
  8. public string zConfirmPassword;
  9.  
  10. public OnSignUpEventArgs(string username, string password, string confirmPassword ) : base()
  11. {
  12. zUsername = username;
  13. zPassword = password;
  14. zConfirmPassword = confirmPassword;
  15. }
  16. }
  17. [Activity(Label = "Dialog_SignUp")]
  18. public class Dialog_SignUp : Activity
  19. {
  20. public static MobileServiceClient Client =
  21. new MobileServiceClient("https://proevents.azurewebsites.net");
  22.  
  23. // public event EventHandler<OnSignUpEventArgs> ZOnSignUpComplete;
  24. protected async override void OnCreate(Bundle savedInstanceState)
  25. {
  26. base.OnCreate(savedInstanceState);
  27. SetContentView(Resource.Layout.Dialog_Sign_Up);
  28.  
  29. var zBtnSignUp = FindViewById<Button>(Resource.Id.btnDialogSignup);
  30. zBtnSignUp.Click += ZBtnSignUp_Click;
  31. EditText zTxtUsername = FindViewById<EditText>(Resource.Id.txtUsername);
  32. zTxtUsername.TextChanged += ValidateInput;
  33. EditText zTxtPassword = FindViewById<EditText>(Resource.Id.txtPassword);
  34. zTxtPassword.TextChanged += ValidateInput;
  35. EditText zTxtConfirmPassword = FindViewById<EditText>(Resource.Id.txtConfirmPassword);
  36. zTxtConfirmPassword.TextChanged += ValidateInput;
  37. }
  38.  
  39. private async void ZBtnSignUp_Click(object sender, EventArgs e)
  40. {
  41. EditText Username = FindViewById<EditText>(Resource.Id.txtUsername);
  42. EditText Password = FindViewById<EditText>(Resource.Id.txtPassword);
  43. EditText ConfirmPassword = FindViewById<EditText>(Resource.Id.txtConfirmPassword);
  44. if (Password.Text == ConfirmPassword.Text)
  45. {
  46. string hashedPassword = PasswordStorage.CreateHash(Password.Text);
  47. string userName = Username.Text.Trim();
  48. users newU = new users { username = userName, password = hashedPassword };
  49. List<users> allUsers = await Client.GetTable<users>().ToListAsync(); Toast.MakeText(this, "Awaits table", ToastLength.Short).Show();
  50. users u = allUsers.FirstOrDefault(x => x.username == newU.username);
  51. if (u == null)
  52. {
  53. DBHelper.InsertNewUser(newU);
  54. Toast.MakeText(this, "User " + newU.username + " created! You can now log in!", ToastLength.Short).Show();
  55. StartActivity(typeof(MainActivity));
  56. }
  57. else
  58. {
  59. Toast.MakeText(this, "User " + u.username + " already exists!", ToastLength.Short).Show();
  60. }
  61. }
  62. else
  63. {
  64. string message = "Passwords don't match.";
  65. Toast.MakeText(this, message, ToastLength.Short).Show();
  66. }
  67. }
  68.  
  69. private void ValidateInput(object sender, TextChangedEventArgs e)
  70. {
  71. EditText input = (EditText)sender;
  72. string pattern = "[^a-zA-Z0-9#?]";
  73. if (Regex.IsMatch(input.Text, pattern))
  74. {
  75. string message = "Input must only contain alphabetic characters, numbers, ? and #";
  76. Toast.MakeText(this, message, ToastLength.Long).Show();
  77. input.Text = "";
  78. }
  79. }
  80. }
Add Comment
Please, Sign In to add comment