Exemplo n.º 1
0
        public IActionResult Register(ClientUser user)
        {
            if (user == null || user.Login == null || user.Password == null)
            {
                return(BadRequest());
            }

            if (user.Login == "" || user.Password == "")
            {
                return(BadRequest(new { errorText = "Login and password must not be empty" }));
            }

            if (_plansDbContext.Users.FirstOrDefault(u => u.Login == user.Login) != null)
            {
                return(Forbid("User with such login already exists"));
            }

            //TODO: PASSWORD INCRIPTING
            var passhash = user.Password;

            var newUser = new User()
            {
                Login        = user.Login,
                PasswordHash = passhash,
                Name         = user.Name,
                LastName     = user.LastName
            };

            _plansDbContext.Users.Add(newUser);
            _plansDbContext.SaveChanges();

            return(Token(user.Login, user.Password));
        }
Exemplo n.º 2
0
        // GET: /<controller>/
        public IActionResult Index()
        {
            var user = new User {
                Name = "Andrey", LastName = "Nasevich", Login = "******"
            };

            _dbContext.Users.Add(user);
            _dbContext.SaveChanges();
            return(Content("Andrey Nasevich was created"));
        }