Exemple #1
0
        public async Task <IActionResult> Login([FromBody] Req <AdminLoginDto> request)
        {
            var rsa = RsaHelper.Instance;

            if (request.CheckSign(rsa.PrivateKey, rsa.RsaModulus, rsa.RsaExponent, out string msg) == false)
            {
                return(Error(msg));
            }
            if (request.DecryptData() == false)
            {
                return(Error("数据错误!"));
            }

            if (CheckSession(SessionSetting.AdminLoginCode, request.Data.Vcode) == false)
            {
                return(Error("验证码错误!"));
            }
            DeleteSession(SessionSetting.AdminLoginCode);

            var admin = await _adminApplication.AdminLogin(request);

            if (admin == null)
            {
                return(Error(request.Message));
            }


            SetSession(SessionSetting.AdminSession, new AdminSessionDto(admin.Id, admin.Name, admin.TrueName, admin.JobNo));
            var setting = await _adminApplication.GetSettingValueByCode("CookieTimes");//cookie 保存时间

            int mins = 0;

            if (setting != null)
            {
                if (int.TryParse(setting.Value, out mins) == false)
                {
                    mins = 180 * 60;
                }
            }
            if (mins < 600)
            {
                mins = 180 * 60;
            }
            string cookie = SetAdminCookieDto(CookieSetting.AdminCookie, CacheHelper.CreateAdminCookieDto(admin, mins));

            await _adminApplication.SetAdminCookie(admin.Id, cookie, request.PasswordString);

            CacheHelper.SetAdminSessionId(admin.Id, cookie, request.PasswordString);


            var rsaKey = RsaUtil.PrivateEncrypt(rsa.PrivateKey, request.PasswordString);

            return(Success(new { RsaKey = rsaKey }));
        }