Пример #1
0
        public async Task <object> exampleLogin(sysUserInfo sysUserInfo)
        {
            try
            {
                //do transaction
                if (string.IsNullOrEmpty(sysUserInfo.LoginName) || string.IsNullOrEmpty(sysUserInfo.LoginPWD))
                {
                    return(ReplyCode.badRequest(ErrorCode.账号密码错误));
                }
                sysUserInfo.LoginPWD = MD5Helper.MD5Encrypt32(sysUserInfo.LoginPWD);
                var user = await service.LoginAsync(sysUserInfo);

                if (user != null)
                {
                    return(ReplyCode.success(new { token = generatorToken(user, "Admin") }));
                }
                else
                {
                    return(ReplyCode.badRequest(ErrorCode.账号密码错误));
                }
            }
            catch (Exception e)
            {
                // if error,unify to handle
                return(ReplyCode.errorRequest(e).ToJsonResult());
            }
        }