public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var user = await _context.Users
                           .SingleOrDefaultAsync(x => x.Username.ToLower() == request.Username.ToLower());

                if (user == null)
                {
                    throw new Exception();
                }

                if (!ValidateUser(user, _passwordHasher.HashPassword(user.Salt, request.Password)))
                {
                    throw new Exception();
                }

                user.RefreshToken = _tokenProvider.GenerateRefreshToken();

                await _context.SaveChangesAsync(cancellationToken);

                return(new Response()
                {
                    AccessToken = _tokenProvider.Get(request.Username, new List <Claim>()
                    {
                    }),
                    UserId = user.UserId,
                    RefreshToken = user.RefreshToken
                });
            }
示例#2
0
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var principal = _tokenProvider.GetPrincipalFromExpiredToken(request.AccessToken);
                var username  = principal.Identity.Name;
                var user      = await _context.Users.FirstOrDefaultAsync(x => x.Username == username);

                var refreshToken = user.RefreshToken;

                if (refreshToken != request.RefreshToken)
                {
                    return(null);
                }

                var accessToken = _tokenProvider.Get(username);

                user.RefreshToken = _tokenProvider.GenerateRefreshToken();

                await _context.SaveChangesAsync(cancellationToken);

                return(new Response
                {
                    AccessToken = accessToken,
                    RefreshToken = user.RefreshToken
                });
            }
            public async Task <Response> Handle(Request request, CancellationToken cancellationToken)
            {
                var geometryFactory = NtsGeometryServices.Instance.CreateGeometryFactory(srid: 4326);

                var physician = await _context.Physicians
                                .Include(x => x.Address)
                                .SingleAsync(x => x.PhysicianId == request.Physician.PhysicianId);

                var address = $"{request.Physician.Address.Street}, {request.Physician.Address.City}, {request.Physician.Address.Province}, {request.Physician.Address.PostalCode}";

                physician.Title        = request.Physician.Title;
                physician.Firstname    = request.Physician.Firstname;
                physician.Lastname     = request.Physician.Lastname;
                physician.PhoneNumber  = request.Physician.PhoneNumber;
                physician.EmailAddress = request.Physician.EmailAddress;
                physician.Website      = request.Physician.Website;

                if (!string.IsNullOrEmpty(_configuration[Constants.GooglePlatformApiKey]))
                {
                    var response = await _googleMapsService.GetCoordinates(address);

                    physician.Address = new Address(
                        request.Physician.Address.Street,
                        request.Physician.Address.City,
                        request.Physician.Address.Province,
                        request.Physician.Address.PostalCode,
                        response.Latitude,
                        response.Longitude,
                        geometryFactory.CreatePoint(new Coordinate(response.Latitude, response.Longitude))
                        );
                }
                else
                {
                    physician.Address = new Address(
                        request.Physician.Address.Street,
                        request.Physician.Address.City,
                        request.Physician.Address.Province,
                        request.Physician.Address.PostalCode
                        );
                }

                await _context.SaveChangesAsync(cancellationToken);

                return(new Response()
                {
                    Physician = physician.ToDto()
                });
            }