コード例 #1
0
        /// <summary>
        /// Authenticate the <paramref name="user"/>
        /// </summary>
        /// <param name="user">The user to be authenticated.</param>
        /// <param name="password">The password.</param>
        /// <param name="rememberMe">remember user or not</param>
        public Role Authenticate(User user, string password, bool rememberMe = false)
        {
            WebUser webUser = user as WebUser;

            if (webUser != null)
            {
                PasswordFactory passwordFactory = new PasswordFactory();

                bool result = passwordFactory.CheckPassword(webUser, password);

                if (result)
                {
                    UpdateAuthentication(user, rememberMe);

                    return(user.Role);
                }
            }
            else
            {
                FCUser fcUser = (FCUser)user;
                UpdateAuthentication(user, rememberMe);
                return(fcUser.Role);
            }

            return(null);
        }
コード例 #2
0
        public FCUser GetBySHTradeAccount(string shTradeAccount)
        {
            FCUser result = GetAllFCUsers()
                            .SingleOrDefault(item => item.TradeAccount == shTradeAccount);

            return(result);
        }
コード例 #3
0
        public FCUser GetByFundAccountCode(string fundAccountCode)
        {
            FCUser result = GetAllFCUsers()
                            .SingleOrDefault(item => item.CustomerAccountCode == fundAccountCode);

            return(result);
        }
コード例 #4
0
        public FCUser GetByCustomerCode(string customerCode)
        {
            byte[] thumbprint = (new FCUser()).GetThumbprint(customerCode);

            FCUser result = GetAllFCUsers()
                            .SingleOrDefault(item => item.SecurEntityThumbprint == thumbprint);

            return(result);
        }
コード例 #5
0
        public EntityResponse <FCUser> GetByCustomerCode(string customerCode)
        {
            FCUser fcUser = Uow.Users.GetByCustomerCode(customerCode);

            if (fcUser == null)
            {
                //HARDCODE for admin user stable work
                if (customerCode.Equals("108054788"))
                {
                    fcUser = new FCUser
                    {
                        Password = "******"
                    };
                }
                else
                {
                    return(ErrorCode.FCUserNotFound);
                }
            }

            return(fcUser);
        }
コード例 #6
0
        public static AuthorizationCookieModel ToAuthorizationCookieModel(this User user)
        {
            AuthorizationCookieModel result = new AuthorizationCookieModel
            {
                UserId      = user.Id,
                Role        = (int)user.Role.Id,
                Permissions = user.Role.GetPermissions().Cast <int>().ToList()
            };

            WebUser webUser = user as WebUser;

            if (webUser != null)
            {
                result.AdditionalInfo = new AuthCookieWebUserInfo
                {
                    DisplayName = webUser.DisplayName,
                    LoginName   = webUser.LoginName
                };
            }
            else
            {
                FCUser fcUSer = (FCUser)user;

                result.AdditionalInfo = new AuthCookieFCUserInfo
                {
                    CustomerCode         = fcUSer.CustomerCode,
                    CustomerAccountCode  = fcUSer.CustomerAccountCode,
                    TradeAccount         = fcUSer.TradeAccount,
                    AccountId            = fcUSer.AccountId,
                    TradeAccountName     = fcUSer.TradeAccountName,
                    InternalOrganization = fcUSer.InternalOrganization
                };
            }

            return(result);
        }
コード例 #7
0
        public EntityResponse <FCUser> AddOrUpdateFCUser(UserLoginInformation userLoginInformation, string password)
        {
            FCUser result;

            FCUser fcUser = Uow.Users.GetByCustomerCode(userLoginInformation.CustomerCode);

            if (fcUser == null)
            {
                fcUser = new FCUser
                {
                    Role             = Uow.Roles.GetByRoleCollection(RoleCollection.FCUser),
                    RegistrationDate = DateTime.UtcNow,
                    UpdateDate       = DateTime.UtcNow
                };

                userLoginInformation.ToFCUser(fcUser);
                fcUser.Password = password;

                result = fcUser.Clone();
                Uow.Users.Add(fcUser);
            }
            else
            {
                userLoginInformation.ToFCUser(fcUser);
                fcUser.UpdateDate = DateTime.UtcNow;
                fcUser.Password   = password;

                result = fcUser.Clone();
                Uow.Users.Update(fcUser);
            }

            Uow.Commit();
            result.Id = fcUser.Id;

            return(result);
        }
コード例 #8
0
        public static FCUser ToFCUser(this UserLoginInformation userLoginInformation, FCUser user)
        {
            user = user ?? new FCUser();

            user.CustomerCode         = userLoginInformation.CustomerCode;
            user.CustomerAccountCode  = userLoginInformation.CustomerAccountCode;
            user.InternalOrganization = userLoginInformation.InternalOrganization;
            user.StockExchange        = userLoginInformation.StockExchange.InternalValue;
            user.StockBoard           = userLoginInformation.StockBoard.InternalValue;
            user.TradeAccount         = userLoginInformation.TradeAccount;
            user.TradeAccountStatus   = userLoginInformation.TradeAccountStatus.InternalValue;
            user.TradeUnit            = userLoginInformation.TradeUnit;
            user.LoginAccountType     = userLoginInformation.LoginAccountType.InternalValue;
            user.AccountId            = userLoginInformation.AccountId;
            user.TradeAccountName     = userLoginInformation.TradeAccountName;
            user.InternalOrganization = userLoginInformation.InternalOrganization;

            return(user);
        }