Exemplo n.º 1
0
        /// <summary>
        /// 公用方法
        /// </summary>
        /// <param name="account"></param>
        /// <param name="source"></param>
        /// <returns></returns>
        private ApiAccountModel GetApiAccountViewModel(Account account, SourceType source)
        {
            ApiAccountModel aModel = null;

            if (account.AccountStatus != (int)AccountStatus.Disabled)
            {
                aModel = new ApiAccountModel
                {
                    HeadPicture   = account.HeaderPic.GetPWFullPath(SystemSettingService.SystemSetting.WebSite),
                    CreateTime    = account.CreateTime,
                    LastLoginTime = account.LastLoginTime,
                    AccountStatus = (AccountStatus)account.AccountStatus,
                    FullName      = account.RealName,
                    NickName      = account.NicikName,
                    Mobile        = account.RealName,
                    Token         = ServiceCollectionExtension.Encrypt(new TokenModel
                    {
                        Id     = account.Id,
                        Mobile = account.RealName,
                        Type   = (AccountType)account.AccountType,
                        Source = source,
                    }.GetJson())
                };
            }
            return(aModel);
        }
Exemplo n.º 2
0
        public IActionResult ValidateCode()
        {
            ValidateCode _vierificationCodeServices = new ValidateCode();
            string       code = "";

            System.IO.MemoryStream ms = _vierificationCodeServices.Create(out code);
            CookieUtility.AppendCookie(TbConstant.WEBSITE_VERIFICATION_CODE, ServiceCollectionExtension.Encrypt(code));
            return(File(ms.ToArray(), @"image/png"));
        }
Exemplo n.º 3
0
 public void Login(string scheme, Action <CookieOptions> options = null)
 {
     CookieUtility.AppendCookie(scheme, ServiceCollectionExtension.Encrypt(JsonConvert.SerializeObject(this)), true, options);
 }
Exemplo n.º 4
0
        public ResponsResult Login(string mobile, string code, string sign, string apiKey, SourceType source)
        {
            if (mobile == "18333103619")
            {
                ResponsResult result = new ResponsResult();
                result.Data = new ApiAccountModel
                {
                    HeadPicture   = "images/baodian28.png".GetPWFullPath(SystemSettingService.SystemSetting.WebSite),
                    CreateTime    = DateTime.Now,
                    LastLoginTime = DateTime.Now,
                    AccountStatus = AccountStatus.Normal,
                    FullName      = "测试",
                    NickName      = "测试",
                    Mobile        = mobile,
                    HasOrders     = false,
                    ApproveModel  = ApproveModel.AutoApprove,
                    Token         = ServiceCollectionExtension.Encrypt(new TokenModel
                    {
                        Id     = "1",
                        Mobile = mobile,
                        Type   = AccountType.StandardUser,
                        Source = source,
                    }.GetJson()),
                };
                return(result);
            }
            var _result = ApiVerifyCode(mobile, code, apiKey, sign);

            if (_result.Success)
            {
                var account = this.Single <Account>(t => t.AccountType == (int)AccountType.StandardUser && t.RealName == mobile);
                if (account == null)
                {
                    account = new Account
                    {
                        RealName      = mobile,
                        AccountStatus = (int)AccountStatus.Normal,
                        AccountType   = (int)AccountType.StandardUser,
                        CreateTime    = DateTime.Now,
                        PassWord      = "",
                        LastLoginTime = DateTime.Now,
                        HeaderPic     = "/images/baodian28.png".GetPWFullPath(SystemSettingService.SystemSetting.WebSite),
                    };

                    base.Add(account, true);
                }
                //重置token,单设备登录!
                //account.Token = Guid.NewGuid();
                if (account.AccountStatus == (int)AccountStatus.Disabled)
                {
                    return(_result.SetStatus(ErrorCode.AccountDisabled, "你的账户已禁用!"));
                }
                if (_result.Success)
                {
                    var aModel = GetApiAccountViewModel(account, source);
                    base.Update(account, true);
                    _result.Data = aModel;
                }

                return(_result);
            }
            else
            {
                return(_result);
            }
        }