コード例 #1
0
ファイル: Authenticate.cs プロジェクト: leonibr/hero-app-wasm
            public async Task <ApiResponse <Result> > Handle(Command request, CancellationToken cancellationToken)
            {
                AppUser user;

                if (!await userService.UserExists(request.Email))
                {
                    var resultr = await userService.CreateMinimunUser(userName : request.Email, password : request.Password);

                    if (!resultr.Succeeded)
                    {
                        return(ApiResponse <Result> .FailureFrom(resultr.Errors.Select(c => c.Description)));
                    }
                }
                else
                {
                    return(ApiResponse <Result> .FailureFrom("User already exists, retrive your access code by sending email to [email protected]"));
                }
                user = await userService.GetUser(request.Email);

                string token = await userService.GenerateToken(userName : request.Email);

                var result = new Result()
                {
                    Authenticated = true,
                    AccessToken   = token,
                    UserId        = user.Id,
                    Message       = "OK",
                };

                return(ApiResponse <Result> .SuccessFrom(result));
            }
コード例 #2
0
ファイル: PostOng.cs プロジェクト: leonibr/hero-app-wasm
 private async Task <bool> NotExistEmail(string userName, CancellationToken cancellationToken)
 {
     return(!await authUser.UserExists(userName));
 }