public async Task <IActionResult> Login([FromBody] PostLoginRequest loginRequest)
 {
     return
         ((await _mediator.Send(_mapper.Map <CreateBearerToken>(loginRequest)))
          .Match <IActionResult>(
              some: token => Created(nameof(Login), _mapper.Map <PostLoginResponse>(token)),
              none: () => Unauthorized()));
 }
Beispiel #2
0
        public async Task <IActionResult> Login([FromBody] PostLoginRequest request)

        {
            Logger?.LogDebug("'{0}' has been invoked", nameof(Login));
            var response = new SingleResponse <UserAdmin>();

            try
            {
                var existingEntity = DbContext.UserAdmin.SingleAsync(x => x.userName == request.userName);
                if (existingEntity != null && existingEntity.Result.password == request.password && existingEntity.Result.isActive == true)
                {
                    response.Model =
                        new UserAdmin
                    {
                        userName = existingEntity.Result.userName,
                        userId   = existingEntity.Result.userId,
                        isActive = existingEntity.Result.isActive
                    };
                }
                else
                {
                    response.DidError = true;
                    if (existingEntity == null)
                    {
                        response.ErrorMessage = "User doesn't exists.";
                    }
                    else if (existingEntity.Result.password != request.password)
                    {
                        response.ErrorMessage = "you have entered wrong password.";
                    }
                    else
                    {
                        response.ErrorMessage = "you have Account is not activate yet.";
                    }
                }
            }
            catch (Exception ex)
            {
                response.DidError     = true;
                response.ErrorMessage = "There was an internal error, please contact to technical support.";

                Logger?.LogCritical("There was an error on '{0}' invocation: {1}", nameof(Login), ex);
            }

            return(response.ToHttpResponse());
        }
Beispiel #3
0
        public async Task <PostLoginResponse> PostLogin(
            [FromBody] PostLoginRequest request,
            [FromServices] LoginService loginService,
            [FromServices] IOptions <ServiceLocation> serviceLocation
            )
        {
            var current = DateTimeOffset.Now;

            using var transaction = transactionManager.BeginTransaction();
            await loginService.LoginAsync(request.Id, request.DeviceId, request.PlayerUid, current);

            await transaction.Commit();

            return(new PostLoginResponse
            {
                AssetsUrl = serviceLocation.Value.AssetUrl,
            });
        }