Ejemplo n.º 1
0
        /// <summary>
        /// Attempts to log the user in
        /// </summary>
        /// <param name="parameter">The <see cref="SecureString"/> passed in from the view for the users password</param>
        /// <returns></returns>
        public async Task LoginAsync(object parameter)
        {
            await RunCommandAsync(() => LoginIsRunning, async() =>
            {
                //Call the server and attempt to login with credentials
                var result = await WebRequests.PostAsync <ApiResponse <UserProfileDetailsApiModel> >(
                    // Set URL
                    RouteHelpers.GetAbsoluteRoute(ApiRoutes.Login),
                    // Create api model
                    new LoginCredentialsApiModel
                {
                    UsernameOrEmail = Email,
                    Password        = (parameter as IHavePassword).SecurePassword.Unsecure()
                });

                // If the response has an error...
                if (await result.HandleErrorIfFailedAsync("Login Failed"))
                {
                    // We are done
                    return;
                }

                // OK successfully logged in... now get users data
                var loginResult = result.ServerResponse.Response;

                // Let the application view model handle what happens
                // with the successful login
                await ViewModelApplication.HandleSuccessfulLoginAsync(loginResult);
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attempts to register a new user
        /// </summary>
        /// <param name="parameter">The <see cref="SecureString"/>passed in from the view for the users password</param>
        /// <returns></returns>
        public async Task RegisterAsync(object parameter)
        {
            // Call the server and attempt to register with the provided credentials
            var result = await WebRequests.PostAsync <ApiResponse <RegisterResultApiModel> >(
                // Set URL
                RouteHelpers.GetAbsoluteRoute(ApiRoutes.Register),
                // Create api model
                new RegisterCredentialsApiModel
            {
                Username = Username,
                Email    = Email,
                Password = (parameter as IHavePassword).SecurePassword.Unsecure()
            });

            // If the reposne has an error...
            if (await result.DisplayErrorIfFailedAsync("Register failed"))
            {
                //We are done
                return;
            }

            // OK successfully registered (and logged in)... now get users data
            var loginResult = result.ServerResponse.ResponseT;

            // Let the application view model handle what happens
            // With the successful login
            await ViewModelApplication.HandleSuccessfulLoginAsync(loginResult);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Attempts to log the user in
        /// </summary>
        /// <param name="parameter">The <see cref="SecureString"/> passed in from the view for the users password</param>
        /// <returns></returns>
        public async Task LoginAsync(object parameter)
        {
            await RunCommandAsync(() => LoginIsRunning, async() =>
            {
                // Call the server and attempt to login with credentials
                // TODO: Move all URLs and API routes to static class in core
                var result = await WebRequests.PostAsync <ApiResponse <UserProfileDetailsApiModel> >(
                    "http://localhost:5000/api/login",
                    new LoginCredentialsApiModel
                {
                    UsernameOrEmail = Email,
                    Password        = (parameter as IHavePassword).SecurePassword.Unsecure()
                });

                // If the response has an error...
                if (await result.DisplayErrorIfFailedAsync("Login Failed"))
                {
                    // We are done
                    return;
                }

                // OK successfully logged in... now get users data
                var loginResult = result.ServerResponse.Response;

                // Let the application view model handle what happens
                // with the successful login
                await ViewModelApplication.HandleSuccessfulLoginAsync(loginResult);
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Attempts to log the user in
        /// </summary>
        /// <param name="parameter">The <see cref="SecureString"/> passed in from the view for the users password</param>
        /// <returns></returns>
        public async Task LoginAsync(object parameter)
        {
            await RunCommandAsync(() => LoginIsRunning, async() =>
            {
                var response = new LoginService <HumanResourcesEmployee>().Login(new HumanResourcesEmployee()
                {
                    Username     = Username,
                    PasswordHash = (parameter as IHavePassword).SecurePassword.Unsecure()
                });

                // If the response has an error...
                if (await response.HandleErrorIfFailedAsync())
                {
                    // We are done
                    return;
                }

                // OK successfully registered (and logged in)... now get users data
                var userId = (Guid)response.Data;

                // Let the application view model handle what happens
                // with the successful login
                await ViewModelApplication.HandleSuccessfulLoginAsync(userId);
            });
        }
        /// <summary>
        /// Attempts to register a new user
        /// </summary>
        /// <param name="parameter">The <see cref="SecureString"/> passed in from the view for the users password</param>
        /// <returns></returns>
        public async Task RegisterAsync(object parameter)
        {
            await RunCommandAsync(() => this.RegisterIsRunning, async() =>
            {
                // Call the server and attempt to register with the provided credentials
                // TODO: Move all URLs and API rroutes to static class in core
                var result = await WebRequests.PostAsync <ApiResponse <RegisterResultApiModel> >("https://localhost:5000/api/register",
                                                                                                 new RegisterCredentialsApiModel
                {
                    Username = Username,
                    Email    = Email,
                    Password = (parameter as IHavePassword).SecurePassword.Unsecure()
                });

                // If there was no response, bad data, or a response with an error message...
                if (await result.DisplayErrorIfFailedAsync("Register Failed"))
                {
                    return;
                }

                // OK successfully registered and logged in ... now get users data
                var loginResult = result.ServerResponse.Response;

                // Let the application view model handle what happens
                // with the successful login
                await ViewModelApplication.HandleSuccessfulLoginAsync(loginResult);
            });
        }