public async Task SaveUserData()
        {
            var userAndProfile = new UserAndProfileModel
            {
                UserName  = IdentityPage.UserName,
                Password  = IdentityPage.Password,
                Gender    = GenderPage.Gender == false ? "Male" : "Female",
                BirthDate = UserPage.BirthDate,
                FirstName = UserPage.FirstName,
                LastName  = UserPage.LastName,
                Email     = AccountPage.Email,
                Skype     = AccountPage.Skype,
                TenantId  = GlobalSettings.TenantId
            };

            var result = await ProfileService.SignUpAsync(userAndProfile);

            if (result != null)
            {
                bool isAuthenticated =
                    await AuthenticationService.LoginAsync(userAndProfile.UserName, userAndProfile.Password);


                if (isAuthenticated)
                {
                    await Nav.Go <Home>();
                }
                else
                {
                    await Alert.Show("Invalid credentials", "Login failure");
                }
            }
        }
Exemple #2
0
        public CreateProfileAndUserCommand(UserAndProfileModel model)
        {
            _model  = model;
            Profile = CreateProfileFromModel(model);
            User    = CreateUserFromModel(model);

            Profile.User = User;
            User.Profile = Profile;
        }
Exemple #3
0
        public Task <UserAndProfileModel> SignUp(UserAndProfileModel profile)
        {
            var builder = new UriBuilder(GlobalSettings.AuthenticationEndpoint);

            builder.Path = $"api/Profiles/";
            var uri = builder.ToString();

            return(_requestProvider.PostAsync(uri, profile));
        }
Exemple #4
0
        private User CreateUserFromModel(UserAndProfileModel model)
        {
            var user = new User()
            {
                Password = model.Password,
                UserName = model.UserName,
                TenantId = model.TenantId
            };

            return(user);
        }
Exemple #5
0
        private UserProfile CreateProfileFromModel(UserAndProfileModel model)
        {
            var profile = new UserProfile()
            {
                BirthDate = model.BirthDate,
                Email     = model.Email,
                FirstName = model.FirstName,
                Gender    = model.Gender,
                LastName  = model.LastName,
                Skype     = model.Skype
            };

            return(profile);
        }
        public Task <UserAndProfileModel> SignUp(UserAndProfileModel profile)
        {
            var userProfile = new UserAndProfileModel
            {
                UserName  = "******",
                Password  = "******",
                Email     = "*****@*****.**",
                Skype     = "me.skype",
                BirthDate = DateTime.Now,
                FirstName = "John",
                LastName  = "Doe",
                Gender    = "Male"
            };

            return(Task.FromResult(userProfile));
        }
        public override async Task OnInitializing()
        {
            await base.OnInitializing();

            var user = new UserAndProfileModel();

            IdentityPage = new IdentityPage();

            AccountPage      = new AccountPage();
            GenderPage       = new GenderPage();
            UserPage         = new UserPage();
            SubscriptionPage = new SubscriptionPage();
            await MyCarousel.Slides.Add(IdentityPage);

            await MyCarousel.Slides.Add(AccountPage);

            await MyCarousel.Slides.Add(GenderPage);

            await MyCarousel.Slides.Add(UserPage);

            await MyCarousel.Slides.Add(SubscriptionPage);
        }
        private void InitializeMessaging()
        {
            // First step
            MessagingCenter.Subscribe <CredentialViewModel>(this, MessengerKeys.CloseCard, (sender) =>
            {
                CloseCommand.Execute(null);
            });

            MessagingCenter.Subscribe <CredentialViewModel, Models.SignUp>(this, MessengerKeys.NextCard, (sender, args) =>
            {
                var signUp = args;

                if (signUp != null)
                {
                    if (Profile.User == null)
                    {
                        Profile.User = new User();
                    }

                    Profile.User.UserName = signUp.Profile.User.UserName;
                    Profile.User.Password = signUp.Profile.User.Password;

                    if (signUp.Navigate)
                    {
                        NextCommand.Execute(null);
                    }
                }
            });

            // Second step
            MessagingCenter.Subscribe <AccountViewModel>(this, MessengerKeys.CloseCard, (sender) =>
            {
                CloseCommand.Execute(null);
            });

            MessagingCenter.Subscribe <AccountViewModel, Models.SignUp>(this, MessengerKeys.NextCard, (sender, args) =>
            {
                var signUp = args;

                if (signUp != null)
                {
                    Profile.Email = signUp.Profile.Email;
                    Profile.Skype = signUp.Profile.Skype;

                    if (signUp.Navigate)
                    {
                        NextCommand.Execute(null);
                    }
                }
            });

            // Third step
            MessagingCenter.Subscribe <GenreViewModel>(GenreViewModel, MessengerKeys.CloseCard, (sender) =>
            {
                CloseCommand.Execute(null);
            });

            MessagingCenter.Subscribe <GenreViewModel, Models.SignUp>(GenreViewModel, MessengerKeys.NextCard, (sender, args) =>
            {
                var signUp = args;

                if (signUp != null)
                {
                    Profile.Gender = signUp.Profile.Gender;

                    if (signUp.Navigate)
                    {
                        NextCommand.Execute(null);
                    }
                }
            });

            // Fourth step
            MessagingCenter.Subscribe <UserViewModel>(UserViewModel, MessengerKeys.CloseCard, (sender) =>
            {
                CloseCommand.Execute(null);
            });

            MessagingCenter.Subscribe <UserViewModel, Models.SignUp>(UserViewModel, MessengerKeys.NextCard, (sender, args) =>
            {
                var signUp = args;

                if (signUp != null)
                {
                    Profile.FirstName = signUp.Profile.FirstName;
                    Profile.LastName  = signUp.Profile.LastName;
                    Profile.BirthDate = signUp.Profile.BirthDate;

                    if (signUp.Navigate)
                    {
                        NextCommand.Execute(null);
                    }
                }
            });

            // Fifth step
            MessagingCenter.Subscribe <PaymentViewModel>(PaymentViewModel, MessengerKeys.CloseCard, (sender) =>
            {
                CloseCommand.Execute(null);
            });

            MessagingCenter.Subscribe <PaymentViewModel, Models.SignUp>(PaymentViewModel, MessengerKeys.NextCard, (sender, args) =>
            {
                var signUp = args;

                if (signUp != null)
                {
                    Profile.Payment = new Payment
                    {
                        CreditCard     = signUp.Profile.Payment.CreditCard,
                        CreditCardType = signUp.Profile.Payment.CreditCardType,
                        ExpirationDate = signUp.Profile.Payment.ExpirationDate
                    };

                    if (signUp.Navigate)
                    {
                        NextCommand.Execute(null);
                    }
                }
            });

            // Last step
            MessagingCenter.Subscribe <SubscriptionViewModel>(SubscriptionViewModel, MessengerKeys.CloseCard, (sender) =>
            {
                CloseCommand.Execute(null);
            });

            MessagingCenter.Subscribe <SubscriptionViewModel, Models.SignUp>(SubscriptionViewModel, MessengerKeys.LastCard, async(sender, args) =>
            {
                if (IsBusy)
                {
                    return;
                }

                try
                {
                    var signUp = args;

                    if (signUp == null)
                    {
                        return;
                    }

                    string gender = "NotSpecified";

                    if (Profile.Gender != null)
                    {
                        if (Profile.Gender == 0)
                        {
                            gender = "Male";
                        }
                        else
                        {
                            gender = "Female";
                        }
                    }

                    var userAndProfile = new UserAndProfileModel
                    {
                        UserName  = Profile.User.UserName,
                        Password  = Profile.User.Password,
                        Gender    = gender,
                        BirthDate = Profile.BirthDate,
                        FirstName = Profile.FirstName,
                        LastName  = Profile.LastName,
                        Email     = Profile.Email,
                        Skype     = Profile.Skype,
                        TenantId  = GlobalSettings.TenantId
                    };

                    IsBusy = true;

                    UserAndProfileModel result = await _profileService.SignUp(userAndProfile);

                    if (result != null)
                    {
                        bool isAuthenticated =
                            await _authenticationService.LoginAsync(userAndProfile.UserName, userAndProfile.Password);

                        if (isAuthenticated)
                        {
                            await NavigationService.NavigateToAsync <MainViewModel>();
                        }
                        else
                        {
                            await DialogService.ShowAlertAsync("Invalid credentials", "Login failure", "Try again");
                        }
                    }
                    else
                    {
                        await DialogService.ShowAlertAsync("Invalid data", "Sign Up failure", "Try again");
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception in sign up {ex}");
                    await DialogService.ShowAlertAsync("Invalid data", "Sign Up failure", "Try again");
                }

                IsBusy = false;
            });
        }
        public IActionResult CreateProfile([FromBody] UserAndProfileModel profile)
        {
            var command = new CreateProfileAndUserCommand(profile);

            return(ProcessCommand(command));
        }
Exemple #10
0
        private async void Next(object navigate)
        {
            IsBusy  = true;
            IsValid = true;
            bool isValid = Validate();

            if (isValid)
            {
                try
                {
                    string gender = "Male";

                    var userAndProfile = new UserAndProfileModel
                    {
                        UserName  = Email.Value,
                        Password  = Password.Value,
                        Gender    = gender,
                        BirthDate = BirthDate,
                        FirstName = FirstName.Value,
                        LastName  = LastName.Value,
                        Email     = Email.Value,
                        TenantId  = GlobalSettings.TenantId
                    };

                    UserAndProfileModel result = await _profileService.SignUp(userAndProfile);

                    if (result != null)
                    {
                        bool isAuthenticated =
                            await _authenticationService.LoginAsync(userAndProfile.UserName, userAndProfile.Password);

                        if (isAuthenticated)
                        {
                            await NavigationService.NavigateToAsync <BaseViewModel>();
                        }
                        else
                        {
                            await DialogService.ShowAlertAsync("Invalid credentials", "Login failure", "Try again");
                        }
                    }
                    else
                    {
                        await DialogService.ShowAlertAsync("Invalid data", "Sign Up failure", "Try again");
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"Exception in sign up {ex}");
                    if (ex == null)
                    {
                        await DialogService.ShowAlertAsync("Invalid data", "Sign Up failure", "Try again");
                    }
                    else
                    {
                        await DialogService.ShowAlertAsync("Invalid data\n", "Sign Up failure", "Try again");
                    }
                }
            }
            else
            {
                await DialogService.ShowAlertAsync("Invalid data", "Please enter correct data and continue", "Try again");

                IsValid = false;
            }

            IsBusy = false;
        }
            public static async Task <UserAndProfileModel> SignUpAsync(UserAndProfileModel profile)
            {
                var uri = $"{GlobalSettings.AuthenticationEndpoint}api/Profiles/";

                return(await BaseApi.Post <UserAndProfileModel>(uri, profile));
            }