예제 #1
0
        public async Task <bool> Register(RegisterInput input)
        {
            var user = await _registrationManager.RegisterAsync(
                input.UserName,
                _syEncode.Get32MD5One(input.PassWord),
                input.Phone
                );

            return(user != null);
        }
예제 #2
0
        public async Task <object> Authenticate([FromBody] LoginDto login)
        {
            Logger.Info("用户登录:" + login.username);
            var user = await _loginManager.loginResult(login.username, _syEncode.Get32MD5One(login.password));

            if (user == null)
            {
                throw new SyMessageBox("密码或账号不正确!");
            }
            if (user.Level != 1)
            {
                throw new SyMessageBox("请使用管理员账号登录!");
            }
            var claims = new[] {
                new Claim(SyClaimTypes.UserName, login.username),
                new Claim(SyClaimTypes.UserId, user.Id.ToString())
            };

            var accessToken = await Task.Run(() => CreateAccessToken(claims));

            Cache.Set(user.Id.ToString(), accessToken);
            return(new { token = accessToken, uuid = user.Id, name = user.Name });
        }