Beispiel #1
0
        public ActionResult Index(ApplicationUser item)
        {
            if (ModelState.IsValid)
            {
                //db.Users.Create(item);
                db.Save();

                //Response.SetCookie(new HttpCookie("userName") {Value = item.Name });
                //Response.SetCookie(new HttpCookie("userID") { Value = Convert.ToString(item.Id)});
            }
            return(View());
        }
Beispiel #2
0
        public void CreateUser(UserDTO userDTO)
        {
            User user = new User();

            if (string.IsNullOrWhiteSpace(userDTO.Password) && userDTO.ChatId == null)
            {
                throw new Exception("Password or ChatId is Required");
            }
            if (db.Users.Find(u => u.Username == userDTO.Username).Count() != 0)
            {
                throw new Exception($"Username {userDTO.Username} is already taken");
            }
            user.ChatId   = userDTO.ChatId;
            user.Username = userDTO.Username;
            byte[] passwordHash;
            byte[] passwordSalt;

            CreatePasswordHash(userDTO.Password, out passwordHash, out passwordSalt);
            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            db.Users.Create(user);
            db.Save();
        }