Exemplo n.º 1
0
 /// <summary>
 /// 注册租户
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="tenantLogOnEntity"></param>
 public async Task <bool> InsertAsync(Tenant entity, TenantLogon tenantLogOnEntity)
 {
     tenantLogOnEntity.Id              = GuidUtils.CreateNo();
     tenantLogOnEntity.TenantId        = entity.Id;
     tenantLogOnEntity.TenantSecretkey = MD5Util.GetMD5_16(GuidUtils.NewGuidFormatN()).ToLower();
     tenantLogOnEntity.TenantPassword  = MD5Util.GetMD5_32(DEncrypt.Encrypt(MD5Util.GetMD5_32(tenantLogOnEntity.TenantPassword).ToLower(), tenantLogOnEntity.TenantSecretkey).ToLower()).ToLower();
     DbContext.GetDbSet <Tenant>().Add(entity);
     DbContext.GetDbSet <TenantLogon>().Add(tenantLogOnEntity);
     return(await DbContext.SaveChangesAsync() > 0);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 租户登陆验证。
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="password">密码(第一次md5加密后)</param>
        /// <returns>验证成功返回用户实体,验证失败返回null|提示消息</returns>
        public async Task <Tuple <Tenant, string> > Validate(string userName, string password)
        {
            var userEntity = await _repository.GetByUserName(userName);

            if (userEntity == null)
            {
                return(new Tuple <Tenant, string>(null, "系统不存在该用户,请重新确认。"));
            }

            if (!userEntity.EnabledMark)
            {
                return(new Tuple <Tenant, string>(null, "该用户已被禁用,请联系管理员。"));
            }

            var userSinginEntity = _repositoryLogon.GetByTenantId(userEntity.Id);

            string inputPassword = MD5Util.GetMD5_32(DEncrypt.Encrypt(MD5Util.GetMD5_32(password).ToLower(), userSinginEntity.TenantSecretkey).ToLower()).ToLower();

            if (inputPassword != userSinginEntity.TenantPassword)
            {
                return(new Tuple <Tenant, string>(null, "密码错误,请重新输入。"));
            }
            else
            {
                TenantLogon userLogOn = _repositoryLogon.GetWhere("UserId='" + userEntity.Id + "'");
                if (userLogOn.AllowEndTime < DateTime.Now)
                {
                    return(new Tuple <Tenant, string>(null, "您的账号已过期,请联系系统管理员!"));
                }
                if (userLogOn.LockEndDate > DateTime.Now)
                {
                    string dateStr = userLogOn.LockEndDate.ToEasyStringDQ();
                    return(new Tuple <Tenant, string>(null, "当前被锁定,请" + dateStr + "登录"));
                }
                if (userLogOn.FirstVisitTime == null)
                {
                    userLogOn.FirstVisitTime = userLogOn.PreviousVisitTime = DateTime.Now;
                }
                else
                {
                    userLogOn.PreviousVisitTime = DateTime.Now;
                }
                userLogOn.LogOnCount++;
                userLogOn.LastVisitTime = DateTime.Now;
                userLogOn.TenantOnLine  = true;
                await _repositoryLogon.UpdateAsync(userLogOn, userLogOn.Id);

                return(new Tuple <Tenant, string>(userEntity, ""));
            }
        }
Exemplo n.º 3
0
        public ActionResult Index(FormCollection form)
        {
            var account  = form["Code"];
            var password = form["Password"];
            var type     = form["LoginType"];

            if (string.IsNullOrWhiteSpace(account) || string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(type) || (type != "email" && type != "mobile"))
            {
                return(Json(new { content = "", title = "请输入用户名/密码", success = false }, JsonRequestBehavior.AllowGet));
            }
            var returnUrl = Request["returnUrl"];
            var svc       = ServiceLocator.Resolve <IModelService>("Internal");
            var logon     = new TenantLogon()
            {
                AccountType = (type == "email")?(int)TenantAccountType.Email:(int)TenantAccountType.Mobile,
                Account     = account,
                Password    = password,
                IP          = Request.UserHostAddress,
                CreatedAt   = DateTime.Now
            };

            try
            {
                svc.Create(logon);
                Session["OwnerID"] = logon.Tenant.OwnerID.Value;
                Session["UserID"]  = logon.Tenant.ID.Value;
            }
            catch (RuleViolatedException error)
            {
                return(Json(new { success = false, content = "", title = error.Message }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception error)
            {
                return(Json(new { success = false, content = "", title = error.Message }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { msg = returnUrl, success = true }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
 /// <summary>
 /// 注册租户
 /// </summary>
 /// <param name="entity"></param>
 /// <param name="tenantLogOnEntity"></param>
 public async Task <bool> InsertAsync(Tenant entity, TenantLogon tenantLogOnEntity)
 {
     return(await _repository.InsertAsync(entity, tenantLogOnEntity));
 }
Exemplo n.º 5
0
        public async Task <IActionResult> RegisterAsync(RegisterViewModel info)
        {
            CommonResult      result            = new CommonResult();
            YuebonCacheHelper yuebonCacheHelper = new YuebonCacheHelper();
            var    vCode = yuebonCacheHelper.Get("ValidateCode" + info.VerifyCodeKey);
            string code  = vCode != null?vCode.ToString() : "11";

            if (code != info.VerificationCode.ToUpper())
            {
                result.ErrMsg = "验证码错误";
                return(ToJsonContent(result));
            }
            if (!string.IsNullOrEmpty(info.Account))
            {
                if (string.IsNullOrEmpty(info.Password) || info.Password.Length < 6)
                {
                    result.ErrMsg = "密码不能为空或小于6位";
                    return(ToJsonContent(result));
                }
                Tenant user = await iService.GetByUserName(info.Account);

                if (user != null)
                {
                    result.ErrMsg = "登录账号不能重复";
                    return(ToJsonContent(result));
                }
            }
            else
            {
                result.ErrMsg = "登录账号不能为空";
                return(ToJsonContent(result));
            }
            Tenant tenant = new Tenant();

            tenant.Id          = GuidUtils.CreateNo();
            tenant.TenantName  = info.Account;
            tenant.Email       = info.Email;
            tenant.CreatorTime = DateTime.Now;
            tenant.EnabledMark = true;
            tenant.DeleteMark  = false;

            TenantLogon tenantLogon = new TenantLogon();

            tenantLogon.TenantPassword = info.Password;
            tenantLogon.AllowStartTime = tenantLogon.LockEndDate = tenantLogon.LockStartDate = tenantLogon.ChangePasswordDate = DateTime.Now;
            tenantLogon.AllowEndTime   = DateTime.Now.AddYears(100);
            tenantLogon.MultiUserLogin = tenantLogon.CheckIPAddress = false;
            tenantLogon.LogOnCount     = 0;
            result.Success             = await iService.InsertAsync(tenant, tenantLogon);

            if (result.Success)
            {
                yuebonCacheHelper.Remove("ValidateCode");
                result.ErrCode = ErrCode.successCode;
                result.ErrMsg  = ErrCode.err0;
            }
            else
            {
                result.ErrMsg  = ErrCode.err43001;
                result.ErrCode = "43001";
            }
            return(ToJsonContent(result));
        }