Exemple #1
0
        public void bl_should_create_person()
        {
            var obj = _bl.CreateUser();

            obj.Uid = "12345";
            Assert.NotNull(obj);
        }
Exemple #2
0
        public IActionResult SignIn([FromBody] UserViewModel vmdl)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            vmdl.Uid = vmdl.Uid.ToLower();
            if (!LDAPAuthenticator.Authenticate(vmdl.Uid, vmdl.Password).IsAuthenticated)
            {
                _log.LogWarning("Failed login attempt for '{0}'", vmdl.Uid);
                return(Unauthorized());
            }
            Person p;

            if (_bl.GetUsers(vmdl.Uid) != null)
            {
                p = _bl.GetUsers(vmdl.Uid);
                _bl.UpdateUser(p);
            }
            else
            {
                p = _bl.CreateUser();
            }
            // Load user data from LDAP and save them into DB
            var ldapUser = LDAPAuthenticator.Authenticate(vmdl.Uid, vmdl.Password);

            vmdl.Refresh(ldapUser);
            vmdl.ApplyChanges(p, _bl);
            _bl.SaveChanges();

            // Create new token from user
            var token = _bl.CreateToken(p);

            return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) }));
        }