Пример #1
0
        public RESTfulModel Login(LoginModel model)
        {
            try
            {
                // 字段验证

                UserInfoModel userInfoModel = userInfoDAL.GetModel(model.Mobile);
                if (userInfoModel != null)
                {
                    string pwd = EncryptHelper.MD5Encrypt(ConfigHelper.Salt + EncryptHelper.MD5Encrypt(model.Password));

                    if (userInfoModel.Password == pwd)
                    {
                        string token = Guid.NewGuid().ToString().Replace("-", "");
                        // 更新token
                        userInfoDAL.UpdateToken(userInfoModel.BusinessID, token, DateTime.Now);

                        // 记录token日志

                        return(new RESTfulModel()
                        {
                            Code = (int)CodeEnum.成功, Msg = string.Format(codeMsgDAL.GetByCode((int)CodeEnum.成功), "登陆成功"), Data = userInfoModel
                        });
                    }
                    else
                    {
                        return(new RESTfulModel()
                        {
                            Code = (int)CodeEnum.密码错误, Msg = codeMsgDAL.GetByCode((int)CodeEnum.密码错误)
                        });
                    }
                }
                else
                {
                    return(new RESTfulModel()
                    {
                        Code = (int)CodeEnum.账号不存在, Msg = codeMsgDAL.GetByCode((int)CodeEnum.账号不存在)
                    });
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(new RESTfulModel()
                {
                    Code = (int)CodeEnum.系统异常, Msg = codeMsgDAL.GetByCode((int)CodeEnum.系统异常)
                });
            }
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="userName">账号</param>
        /// <param name="password">密码</param>
        /// <returns></returns>
        public ResponseModel <string> Login(string userName, string password)
        {
            string md5Pwd = EncyptHelper.MD5(password);

            var model = dal.GetModel(q => q.User_Account == userName && q.User_Pwd == md5Pwd);

            ResponseModel <string> response = new ResponseModel <string>();

            if (model != null)
            {
                var token = tokenDal.GetModel(p => p.User_ID == model.User_ID);

                if (token != null)
                {
                    token.OverdueDate = DateTime.Now.AddHours(2);
                    tokenDal.Update(token);

                    if (tokenDal.SaveChanges())
                    {
                    }
                }
                else
                {
                    token.OverdueDate = DateTime.Now.AddHours(2);
                    //token.Token
                    tokenDal.Update(token);
                }

                response.success = true;
                response.msg     = "登录成功";
                response.data    = "{}";
                return(response);
            }
            else
            {
                response.success = false;
                response.msg     = "账号密码错误";
                response.data    = "{}";
                return(response);
            }
        }