//validate login private void Validate(ErrorBucket errors) { // do basic data presence validation... if (string.IsNullOrEmpty(PhoneNumber)) { errors.AddError(res.GetString("RequiredPhone")); } if (string.IsNullOrEmpty(Password) || Password.Length < 6) { errors.AddError(res.GetString("ValidPassword")); } }
//validate register private void ValidateSignUp(ErrorBucket errors) { // do basic data presence validation... if (string.IsNullOrEmpty(FullName)) { errors.AddError(res.GetString("RequiredName")); } if (string.IsNullOrEmpty(Password)) { errors.AddError(res.GetString("RequiredPassword")); } if (string.IsNullOrEmpty(Confirm)) { errors.AddError(res.GetString("txtConfirm/Text")); } // check the passwords... if (!(string.IsNullOrEmpty(Password)) && Password != Confirm) { errors.AddError(res.GetString("MatchPassword")); } if (!(string.IsNullOrEmpty(Password)) && Password.Length < 6) { errors.AddError(res.GetString("ValidPassword")); } if (string.IsNullOrEmpty(Email)) { errors.AddError(res.GetString("RequiredEmail")); } if (string.IsNullOrEmpty(PhoneNumber)) { errors.AddError(res.GetString("RequiredPhone")); } if ((string.IsNullOrEmpty(PhoneNumber)) && PhoneNumber.Length < 12) { errors.AddError(res.GetString("InvalidPhone")); } if (string.IsNullOrEmpty(Code)) { errors.AddError(res.GetString("RequiredCode")); } }
//register private async void DoRegister(CommandExecutionContext context) { ErrorBucket errors = new ErrorBucket(); // if we don't have a context, create one... if (context == null) { context = new CommandExecutionContext(); } // validate... ValidateSignUp(errors); // ok? if (!(errors.HasErrors)) { // get a handler... var proxy = TinyIoCContainer.Current.Resolve <IRegisterServiceProxy>(); await Host.ToggleProgressBar(true, res.GetString("SigningUp")); var result = await proxy.RegisterAsync(FullName, PhoneNumber, Password, SelectedLocation, Code, Email); // ok? if (!(result.HasErrors)) { if (result.status == "success") { await Host.ToggleProgressBar(true, string.Format(res.GetString("registered"), FullName)); //assign new token to global class MFundiRuntime.LogonToken = result.token; // save logontoken localSettings.Values["LogonToken"] = result.token; //save Location localSettings.Values["Location"] = SelectedLocation; localSettings.Values["FullName"] = FullName; localSettings.Values["PhoneNumber"] = PhoneNumber; localSettings.Values["Email"] = Email; await Host.ToggleProgressBar(false); Host.ShowView(typeof(IHomePageViewModel)); } else { await Host.ToggleProgressBar(false); errors.AddError(result.status); await Host.ShowAlertAsync(errors); } } else { errors.CopyFrom(result); await Host.ToggleProgressBar(false); } } // errors? if (errors.HasErrors) { await Host.ShowAlertAsync(errors); } }