public async Task <Cobuyer> AddCobuyerToProspectAsync(int prospectId, Cobuyer cobuyer)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                return(await _cobuyerRepository.AddCobuyerToProspectAsync(prospectId, cobuyer, authResult.AccessToken));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                _dialogService.ShowAlertAsync("Seems like there was a problem.", "Oops", "Close");
                return(null);
            }
        }
Beispiel #2
0
        public async Task <bool> UpdateTrafficCardResponse(int prospectAddressNumber, List <TrafficCardResponse> response)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                return(await _responseRepository.UpdateTrafficCardResponseAsync(prospectAddressNumber, response, authResult.AccessToken));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                _dialogService.ShowAlertAsync("Seems like there was a problem." + ex.Message, "Oops", "Close");
                return(false);
            }
        }
        public async Task <List <Community> > GetCommunitiesByDivision(string divisionCode, bool activeOnly)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                return(await _communityRepository.GetCommunitiesByDivisionAsync(authResult.AccessToken, divisionCode, activeOnly));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                _dialogService.ShowAlertAsync("Seems like there was a problem." + ex.Message, "Oops", "Close");
                return(default(List <Community>));
            }
        }
Beispiel #4
0
        public async Task <TrafficSource> GetTrafficSourceDetails(int sourceId)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                return(await _trafficSourceRepository.GetTrafficSourceDetailsAsync(sourceId, authResult.AccessToken));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                _dialogService.ShowAlertAsync("Seems like there was a problem." + ex.Message, "Oops", "Close");
                return(default(TrafficSource));
            }
        }
Beispiel #5
0
        public ActionResult Login(UserLoginViewModel loginViewModel, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var userAuthenticationResult = _userService.AuthenticateUser(loginViewModel.Username,
                                                                             loginViewModel.Password);

                if (userAuthenticationResult.Status == ResultStatus.Success)
                {
                    var authenticatedUser = userAuthenticationResult.GetData();

                    var whereToRedirect = _authenticator.AuthenticateUser(authenticatedUser.Username, loginViewModel.RememberMe, returnUrl);

                    // IF the Authenticator does not return a url something went wrong
                    if (whereToRedirect == "")
                    {
                        ModelState.AddModelError("", "Failed to authenticate. Please try again.");
                        return(View(loginViewModel));
                    }

                    return(Redirect(whereToRedirect));
                }
                else
                {
                    // we are going to add an error to the model state
                    ModelState.AddModelError("", "Invalid username of password. Please try again");
                    return(View(loginViewModel));
                }
            }
            else
            {
                return(View(loginViewModel));
            }
        }
Beispiel #6
0
        public async Task <BuyerDecisions> GetBuyerDecisionsAsync(int prospectId)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                var decisions = await _buyerDecisionsRepository.GetBuyerDecisionsAsync(prospectId, authResult.AccessToken);

                return(decisions ?? new BuyerDecisions {
                    ProspectAddressNumber = prospectId
                });
            }

            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                _dialogService.ShowAlertAsync("Seems like there was a problem.", "Oops", "Close");
                return(null);
            }
        }
        public async Task <AddressBook> AssignProspectToLoggedInUserAsync(string communityNumber, int prospectId)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                var user = await _userService.GetUserById(authResult.UserInfo.DisplayableId);

                var result = await _prospectRepository.AssignProspectToSalespersonAsync(communityNumber, prospectId, user.AddressNumber, authResult.AccessToken);

                return(user.AddressBook);
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                await _dialogService.ShowAlertAsync("Seems like there was a problem." + ex.Message, "Oops", "Close");

                return(null);
            }
        }
Beispiel #8
0
        private async Task <User> getUser(string userId = null)
        {
            var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

            if (userId == null)
            {
                userId = authResult.UserInfo.DisplayableId;
            }
            var user = await _userRepository.GetUserByIdAsync(userId, authResult.AccessToken);

            return(user);
        }
        public void PerformUserSecurityOperations(User user)
        {
            // authenticate user
            _authenticator.AuthenticateUser(user.UserName, user.Password);

            // authorize user
            bool canUserBeAuthorized = _authorizer.CanAuthorizeUser(user.UserName);

            if (canUserBeAuthorized)
            {
                _authorizer.AuthorizeUser(user.UserName);
            }
        }
Beispiel #10
0
        private async Task <List <UserDefinedCode> > getUserDefinedCodes(string productCode, string group)
        {
            try
            {
                var authResult = await _authenticator.AuthenticateUser(Constants.PrivateKeys.ProspectMgmtRestResource);

                return(await _userDefinedCodeRepository.GetUserDefinedCodesAsync(productCode, group, authResult.AccessToken));
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                await _dialogService.ShowAlertAsync("Seems like there was a problem." + ex.Message, "Oops", "Close");

                return(new List <UserDefinedCode>());
            }
        }
        public virtual async Task <IHttpActionResult> CreateToken([FromBody] TokenRequest tokenRequest)
        {
            var user = await _auth.AuthenticateUser(tokenRequest.Identity, tokenRequest.Secret);

            if (user == null)
            {
                return(Unauthorized());
            }

            var claims = new Dictionary <string, object>()
            {
                { "identity", user.Identity },
                { "roles", user.Roles }
            };

            return(Ok(await _tokens.CreateToken(claims)));
        }