public async void OnLogin()
        {
            if (Username == null || UserPassword == null || Username == "" || UserPassword == "")
            {
                MessagingCenter.Send <UserProfileViewModel, string>(this, "LoginFailure", "Please provide Username/Password");
            }
            else
            {
                IsServiceInProgress = true;

                Models.LoginRequestModel loginRequestModel = new Models.LoginRequestModel("App", Username, SelectedView, UserPassword);
                var message = await App.TodoManager.Login(loginRequestModel);

                if (message == "Success")
                {
                    var data = App.LoginResponse;

                    if (data.Profile == null || data.Profile == "")
                    {
                        MessagingCenter.Send <UserProfileViewModel, String>(this, "LoginSuccess", "NAV");
                    }
                    else
                    {
                        MessagingCenter.Send <UserProfileViewModel, String>(this, "LoginSuccess", "AV");
                    }
                }
                else
                {
                    MessagingCenter.Send <UserProfileViewModel, string>(this, "LoginFailure", message);
                }

                IsServiceInProgress = false;
            }
        }
Esempio n. 2
0
        async void HandleAction(Models.FacebookUser arg1, string arg2)
        {
            try
            {
                App.FacebookUser = arg1;
                App.access_code  = arg1.Token;

                var loginRequestModel = new Models.LoginRequestModel("App", arg1.Email, App.SelectedView, "fb@trainme");
                var message           = await App.TodoManager.Login(loginRequestModel);

                if (message == "Success")
                {
                    ViewModels.SignupViewModel signupViewModel = new ViewModels.SignupViewModel();
                    signupViewModel.EmailAddress = App.FacebookUser.Email;
                    signupViewModel.Password     = "******";
                    //signupViewModel.Name = arg1.FirstName + " " + arg1.LastName;
                    signupViewModel.UserIcon     = arg1.Picture;
                    signupViewModel.SelectedView = App.SelectedView;

                    var data = App.LoginResponse;

                    if (data.Profile == null || data.Profile == "")
                    {
                        await this.Navigation.PushAsync(new Views.UserInformationPage(signupViewModel));
                    }
                    else
                    {
                        var member = App.LoginResponse;
                        CredentialsService.SaveCredentials(App.FacebookUser.Email, "fb@trainme", member, App.FacebookUser, userType: App.SelectedView);
                        Application.Current.MainPage = new RootPage(App.SelectedView);
                    }
                }
                else
                {
                    await DisplayAlert("Alert", message, "Ok");
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Alert", ex.Message, "Ok");
            }
        }
Esempio n. 3
0
 public Task <String> Login(Models.LoginRequestModel loginRequestModel)
 {
     return(restService.LoginAsync(loginRequestModel));
 }
Esempio n. 4
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            if (App.access_code != null)
            {
                userProfileViewModel.FacebookData();
            }

            MessagingCenter.Subscribe <Object, string>(this, "InstagramLogin", async(arg1, arg2) =>
            {
                try
                {
                    if (!string.IsNullOrEmpty(arg2))
                    {
                        var instaResult = await App.TodoManager.GetInstaToken(arg2);

                        if (instaResult == "Success")
                        {
                            userProfileViewModel.IsServiceInProgress = true;
                            //var result = await App.TodoManager.GetInstagramInfo(App.InstaAccessToken);
                            await App.TodoManager.GetInstagramMedia(App.InstaAccessToken);

                            var loginRequestModel = new Models.LoginRequestModel("Fb", App.InstagramUser.data.username, App.SelectedView, "fb@trainme");
                            var message           = await App.TodoManager.Login(loginRequestModel);

                            if (message.Equals("Success"))
                            {
                                ViewModels.SignupViewModel signupViewModel = new ViewModels.SignupViewModel();
                                signupViewModel.EmailAddress = App.InstagramUser.data.username;
                                signupViewModel.Password     = "******";
                                //signupViewModel.Name = App.InstagramUser.data.full_name;
                                signupViewModel.UserIcon     = App.InstagramUser.data.profile_picture;
                                signupViewModel.SelectedView = App.SelectedView;

                                var data = App.LoginResponse;

                                if (data.Profile == null || data.Profile == "")
                                {
                                    await this.Navigation.PushAsync(new Views.UserInformationPage(signupViewModel));
                                }
                                else
                                {
                                    //var member = App.SelectedView == "Trainee" ? App.LoginResponse : App.TrainerData;
                                    CredentialsService.SaveCredentials(App.InstagramUser.data.username, "fb@trainme", App.LoginResponse, instagramUser: App.InstagramUser, instagramMedia: App.InstagramMedia, userType: App.SelectedView);
                                    Application.Current.MainPage = new RootPage(App.SelectedView);
                                }
                            }
                            else
                            {
                                await DisplayAlert("Alert", message, "Ok");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                    await DisplayAlert("Alert", "something went wrong", "Ok");
                }
                userProfileViewModel.IsServiceInProgress = false;
            });

            MessagingCenter.Subscribe <UserProfileViewModel, String>(this, "LoginSuccess", async(sender, message) =>
            {
                MessagingCenter.Unsubscribe <UserProfileViewModel>(this, "LoginSuccess");
                MessagingCenter.Unsubscribe <UserProfileViewModel>(this, "LoginFailure");
                if (message == "NAV")
                {
                    if (userProfileViewModel.UserPassword == "fb@trainme")
                    {
                        ViewModels.SignupViewModel signupViewModel = new ViewModels.SignupViewModel();
                        signupViewModel.EmailAddress = userProfileViewModel.Username;
                        signupViewModel.Password     = userProfileViewModel.UserPassword;
                        //signupViewModel.Name = App.FacebookProfile.Name;
                        //signupViewModel.UserIcon = App.FacebookProfile.Picture.Data.Url;
                        signupViewModel.SelectedView = App.SelectedView;


                        await this.Navigation.PushAsync(new Views.UserInformationPage(signupViewModel));
                    }
                    else
                    {
                        await DisplayAlert("Alert", "Incorrect Username or Password. Please try again.", "OK");
                    }
                }
                else
                {
                    if (userProfileViewModel.IsRememberMe)
                    {
                        var member = App.LoginResponse;
                        CredentialsService.SaveCredentials(userName: App.LoginResponse.Email, password: App.LoginResponse.Password, member: member, userType: App.SelectedView);
                    }

                    Application.Current.MainPage = new NavigationPage(new RootPage(userProfileViewModel.SelectedView));
                }
            });

            MessagingCenter.Subscribe <UserProfileViewModel, String>(this, "LoginFailure", async(sender, message) =>
            {
                await DisplayAlert("Alert", message, "Ok");
            });
        }