Exemplo n.º 1
0
        public async Task <IActionResult> CreateNewAccount(CreateNewAccountModel model)
        {
            List <User> users = await context.Users.AsNoTracking().ToListAsync();

            User database_user = users.SingleOrDefault(u => u.Name == model.Username);

            if (database_user == null)
            {
                string _password = hashData.ComputeHashSha512(model.Password, model.Username);

                User user = new User {
                    Name = model.Username, Password = _password, Role = Role.User
                };

                context.Add(user);
                await context.SaveChangesAsync();

                return(View("AccountCreated"));
            }
            else
            {
                model.ErrorMessage = "This username has already been taken!";

                return(View(model));
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("MicrocontrollerID,MicrocontrollerName")] Microcontroller microcontroller)
        {
            microcontroller.UserID = Convert.ToInt32(this.User.FindFirstValue(ClaimTypes.NameIdentifier));

            using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
            {
                byte[] val = new byte[4];
                rng.GetBytes(val);

                int value = BitConverter.ToInt32(val, 0);

                string _AuthKey = hashData.ComputeHashSha512(value.ToString(), microcontroller.UserID.ToString());
                _AuthKey = _AuthKey.Substring(0, 12);
                microcontroller.APIauthKey = _AuthKey;
            }


            if (ModelState.IsValid)
            {
                _context.Add(microcontroller);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(microcontroller));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("UserID,Name,Password,Role")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }