Beispiel #1
0
        public async Task <TokenDto> LoginAsync(string email, string password)
        {
            var user = await _userRepository.GetAsync(email);

            if (user == null || user.Password != password)
            {
                throw new Exception("Invalid credentials");
            }
            var jwt = _jwtHandler.CreateTokem(user.Id, user.Role);

            return(new TokenDto
            {
                Token = jwt.Token,
                Expires = jwt.Expires,
                Role = user.Role
            });
        }
        public async Task <TokenDto> LoginAsync(string email, string password)
        {
            var user = await _userRepository.GetAsync(email);

            if (user == null || !VerifyPasswordHash(password, user.Password, user.PasswordSalt))
            {
                throw new Exception("Invalid credentials");
            }
            string name;
            string logoUrl;

            if (user.Role == "company")
            {
                name = user.CompanyProfile.CompanyName;
                if (user.CompanyProfile.Photos.Count != 0)
                {
                    logoUrl = user.CompanyProfile.Photos.SingleOrDefault(x => x.Description == "logo").Url;
                }
                else
                {
                    logoUrl = null;
                }
            }
            else
            {
                name    = user.ModeratorProfile.ContactPerson;
                logoUrl = null;
            }
            var jwt = _jwtHandler.CreateTokem(user.Id, user.Role, name);

            return(new TokenDto
            {
                Token = jwt.Token,
                Expires = jwt.Expires,
                Role = user.Role,
                LogoUrl = logoUrl,
                IsCompany = user.IsCompany
            });
        }