Beispiel #1
0
        public string RegisterAndLoginUser(NewUserModel model)
        {
            model.RoleId = globalConfig.IdRoleDefault;
            UserEntity modelEntity = this.mapper.Map <UserEntity>(model);

            UserEntity newUser = repository.RegisterNewUser(modelEntity);

            UserModel tokenModel = mapper.Map <UserModel>(newUser);

            string token = authentication.GenerateToken(tokenModel);


            return(token);
        }
Beispiel #2
0
        public IActionResult Login(LoginModel model)
        {
            var innerModel = mapper.Map <UserEntity>(model);

            var foundUser = repository.GetUserByUserName(innerModel.UserName);

            if (foundUser == null)
            {
                return(BadRequest($"Usuario { innerModel.UserName } no existe."));
            }

            if (foundUser.Password != innerModel.Password)
            {
                return(BadRequest("Password incorrecta."));
            }

            string rawResponse = authentication.GenerateToken(mapper.Map <UserModel>(foundUser));

            return(Ok(new { token = rawResponse }));
        }