Beispiel #1
0
        public async void Initialize(UserProfilePage page)
        {
            this.userProfilePage = page;

            //disable controls if facebook user
            IsDisableControls = !Settings.IsFacebookUser;

            if (Settings.IsFacebookUser)
            {
                Avatar      = Settings.Avatar;
                Name        = Settings.Name;
                GenderIndex = Settings.Gender.ToLower() == Constants.MALE ? 0 : 1;
                Email       = Settings.Email;
            }
            else
            {
                //BAMApp User
                IsBusy         = true;
                LoadingMessage = "Loading...";

                BAMAppUser user = await ServiceLocator.AzureService.GetById <BAMAppUser>(Settings.UserId);

                Avatar      = user.Avatar;
                Name        = user.Name;
                GenderIndex = user.Gender.ToLower() == Constants.MALE ? 0 : 1;
                Email       = user.Email;
                Birthday    = user.Birthday;
                PhoneNumber = user.PhoneNumber;
                ZipCode     = user.ZipCode;
            }

            IsBusy = false;
        }
Beispiel #2
0
        public async void SignIn(object obj)
        {
            try
            {
                LoadingMessage = "Signing In";
                IsBusy         = true;

                //check whether the user exists in Azure table
                //and get user id and save in local settings for single-sign on
                if (email != null && email.Contains("@"))
                {
                    BAMAppUser user = await ServiceLocator.AzureService.GetUserByEmail(email);

                    if (user != null)
                    {
                        if (user.Password == password)
                        {
                            Settings.UserId = user.Id;
                            //for home page master page labels (name, avatar) the following are stored in settings
                            Settings.Avatar = user.Avatar;
                            Settings.Name   = user.Name;
                            await TakeToHomePage();
                        }
                        else
                        {
                            await signInPage.DisplayAlert("Sorry", "Invalid password!", "Try again");
                        }
                    }
                    else
                    {
                        await signInPage.DisplayAlert("Sorry", "Invalid email id!", "Try again");
                    }
                }
                else
                {
                    await signInPage.DisplayAlert("Sorry", "Invalid email id!", "Enter correct email id");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("OH NO!" + ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Beispiel #3
0
        public async void Update(object obj)
        {
            IsBusy         = true;
            LoadingMessage = "Updating...";

            BAMAppUser user = CreateUserInstance();

            var originalUser = await ServiceLocator.AzureService.GetById <BAMAppUser>(Settings.UserId);

            user.Id       = originalUser.Id;
            user.Password = originalUser.Password;


            await ServiceLocator.AzureService.Update(user);

            Initialize(userProfilePage);

            IsBusy = false;
        }
Beispiel #4
0
        public async void Delete(object obj)
        {
            bool answer = await userProfilePage.DisplayAlert("Are you sure?", "All coupons will be lost", "ok", "cancel");

            if (answer)
            {
                IsBusy         = true;
                LoadingMessage = "Deleting...";

                BAMAppUser user = await ServiceLocator.AzureService.GetById <BAMAppUser>(Settings.UserId);

                await ServiceLocator.AzureService.Delete(user);

                await ServiceLocator.AuthenticationService.LogoutAsync(
                    ServiceLocator.AzureService.MobileService);

                userProfilePage.Navigation.InsertPageBefore(new SignInPage(), userProfilePage.Navigation.NavigationStack.First());
                await userProfilePage.Navigation.PopToRootAsync();
            }

            IsBusy = false;
        }
Beispiel #5
0
        public async void SignUp(object obj)
        {
            IsBusy         = true;
            LoadingMessage = "Creating Account...";

            Regex regex = new Regex("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{6,20}$");

            if (
                string.IsNullOrEmpty(name) ||
                string.IsNullOrEmpty(email) ||
                string.IsNullOrEmpty(password) ||
                string.IsNullOrEmpty(confirmPassword) ||
                string.IsNullOrEmpty(gender) ||
                birthday == null
                )
            {
                await signUpPage.DisplayAlert("Error", "Fields with * cannot be empty", "Ok");
            }
            else if (!regex.Match(password).Success)
            {
                await signUpPage.DisplayAlert("Error",
                                              "Passwords should be 6 to 20 chars long and should be a combination of numbers, small and capital letters",
                                              "Ok");
            }
            else if (!password.Equals(confirmPassword))
            {
                await signUpPage.DisplayAlert("Error", "Passwords doesn't match", "Ok");
            }
            else
            {
                //Check if email id already exists
                if (await ServiceLocator.AzureService.GetUserByEmail(email) != null)
                {
                    IsBusy = false;
                    await signUpPage.DisplayAlert("Sorry", "Email id already exists!", "Please sign in or enter different email id");

                    return;
                }

                //Create BAMPppUser Object
                BAMAppUser user = CreateUserInstance();
                user.Password = Password;
                await ServiceLocator.AzureService.Add(user);

                //if inserted successfully navigate
                BAMAppUser savedUser = await ServiceLocator.AzureService.GetUserByEmail(user.Email);

                if (savedUser != null)
                {
                    //save userID and user info to local settings
                    Settings.UserId = savedUser.Id;
                    Settings.Avatar = user.Avatar;
                    Settings.Name   = user.Name;

                    //remove  sign up page from navigation stack
                    signUpPage.Navigation.InsertPageBefore(new HomePage(), signUpPage.Navigation.NavigationStack.First());
                    await signUpPage.Navigation.PopToRootAsync();
                }
            }

            IsBusy = false;
        }