コード例 #1
0
        public static string AuthenticateUser(LoginViewModel model)
        {
            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        var user = new UserDTO
                        {
                            UserID   = model.UserName,
                            Password = Encryption.GetMd5Sum(model.Password)
                        };
                        var request = new AuthenticateUserRequest {
                            User = user
                        };

                        AuthenticateUserResponse response = _certonaService.AuthenticateUser(request);
                        if (!response.Success)
                        {
                            return(Utilities.ParseServiceErrors(response.Errors));
                        }
                        if (response.User == null || response.User.UserID == null)
                        {
                            return("Invalid user account.");
                        }

                        var userDetailsRequest = new GetUserAccountApplicationFeaturesRequest {
                            User = response.User
                        };
                        var userDetailsResponse = _certonaService.GetUserAccountApplicationFeatures(userDetailsRequest);
                        if (userDetailsResponse.Success)
                        {
                            response.User.Accounts = userDetailsResponse.Accounts;
                        }

                        FormsAuth.SetAuthCookie(response.User, false);

                        ReportingStartDate = DateTime.Now.AddDays(-30);
                        ReportingEndDate   = DateTime.Now;
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return("");
        }
コード例 #2
0
        /*
         * public static ReportsViewModel GetRecommendations(string applicationId)
         * {
         *  var model = new ReportsViewModel();
         *  model.Recommendations = new List<string>();
         *
         *  try
         *  {
         *      using (_certonaService = new CertonaServiceClient())
         *      {
         *          try
         *          {
         *              UserDTO user = FormsAuthenticationWrapper.User;
         *
         *              var getRequest = new GetApplicationSchemesRequest() { ApplicationID = applicationId, User = user };
         *              var getResponse = _certonaService.GetApplicationSchemes(getRequest);
         *              if (getResponse.Success && getResponse.Schemes != null && getResponse.Schemes.Count > 0)
         *              {
         *                  foreach (var scheme in getResponse.Schemes)
         *                  {
         *                      model.Recommendations.Add(scheme.SchemeName);
         *                  }
         *              }
         *
         *          }
         *          catch (TimeoutException exception)
         *          {
         *              _certonaService.Abort();
         *              throw;
         *          }
         *          catch (CommunicationException exception)
         *          {
         *              _certonaService.Abort();
         *              throw;
         *          }
         *      }
         *  }
         *  catch (Exception ex)
         *  {
         *      _certonaService.Abort();
         *      throw;
         *  }
         *
         *  return model;
         * }
         */

        public static ReportsViewModel GetUserAccountApplicationFeatures()
        {
            var model = new ReportsViewModel();

            model.ApplicationList = new List <string>();

            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        UserDTO user       = FormsAuthenticationWrapper.User;
                        var     getRequest = new GetUserAccountApplicationFeaturesRequest()
                        {
                            User = user
                        };
                        var getResponse = _certonaService.GetUserAccountApplicationFeatures(getRequest);
                        if (getResponse.Success && getResponse.Accounts[0].Applications != null && getResponse.Accounts[0].Applications.Count > 0)
                        {
                            model.ApplicationList =
                                getResponse.Accounts.Where(m => m.AccountID == user.LastAccountID)
                                .SelectMany(m => m.Applications)
                                .Select(m => m.ApplicationID)
                                .ToList();
                        }
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                _certonaService.Abort();
                throw;
            }

            return(model);
        }