Пример #1
0
        public async Task <ActionResult <dynamic> > login([FromBody] CttUser userData)
        {
            CttUser loggedUser = authService.login(userData.Email, userData.Pass);

            if (loggedUser == null)
            {
                return(BadRequest());
            }

            var token = TokenService.GenerateToken(loggedUser);

            var userDTO = new //DTO Should be a proper DTO class...
            {
                Email     = loggedUser.Email,
                FullName  = loggedUser.FullName,
                BirthDate = loggedUser.BirthDate,
                Nif       = loggedUser.Nif,
                CcNumber  = loggedUser.CcNumber,
                Locality  = loggedUser.Locality,
                Iban      = loggedUser.Iban,
                Phone     = loggedUser.Phone
            };

            return(Ok(new
            {
                user = userDTO,
                token = token
            }));
        }
Пример #2
0
        public CttUser registerUser(CttUser user)
        {
            dbContext.Add(user);
            dbContext.SaveChanges();

            return(getUser(user.Email));
        }
Пример #3
0
        public IActionResult updateUserDetails([FromBody] CttUser user)
        {
            CttUser updatedUser = authService.updateUser(user);

            if (updatedUser == null)
            {
                return(BadRequest());
            }

            return(Ok(updatedUser));
        }
Пример #4
0
        public IActionResult register([FromBody] CttUser user)
        {
            bool isEmailFree = authService.isEmailFree(user.Email);

            if (isEmailFree)
            {
                return(Ok(0)); //0 = No Error;
            }

            return(Ok(1)); //1 = Error;
        }
Пример #5
0
        public CttUser updateUser(CttUser user)
        {
            bool isNull = user.GetType().GetProperties()
                          .All(p => p.GetValue(user) != null);

            if (isNull)
            {
                return(null);
            }

            return(_authRepository.updateUser(user));
        }
Пример #6
0
        //string hashedPassword = hash(password);
        //_authRepository.registerNewEmail(email, hashedPassword);

        public CttUser registerUser(CttUser user)
        {
            CttUser persistedUser = _authRepository.getUser(user.Email);

            if (persistedUser != null)
            {
                return(null);
            }

            user.Pass = hash(user.Pass);
            return(_authRepository.registerUser(user));
        }
Пример #7
0
        public CttUser login(string email, string password)
        {
            CttUser user          = _authRepository.getUser(email);
            bool    isPassCorrect = false;

            if (user != null)
            {
                isPassCorrect = verify(password, user.Pass);
            }

            return(isPassCorrect ? user : null);
        }
Пример #8
0
        public static string GenerateToken(CttUser user)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(Settings.Secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Email, user.Email.ToString()),
                }),
                Expires            = DateTime.UtcNow.AddHours(2),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
Пример #9
0
        public IActionResult registerUserDetails([FromBody] CttUser user)
        {
            CttUser persistedUser = authService.registerUser(user);

            return(Ok(persistedUser));
        }
Пример #10
0
 public CttUser updateUser(CttUser user)
 {
     dbContext.Update(user);
     return(getUser(user.Email));
 }
Пример #11
0
        public bool isEmailFree(string email)
        {
            CttUser user = _authRepository.getUser(email);

            return(user == null);
        }