Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "ID,FirstName,LastName,Email,Mobile,DateOfBirth,Password")] User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);

                user.Password = GetMD5(user.Password);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Ejemplo n.º 2
0
        public OAuthController(UsersDb usersDb, AppsDb appsDb,
                               IPasswordHasher passwordHasher, ITokenService tokenService)
        {
            _usersDb        = usersDb;
            _appsDb         = appsDb;
            _passwordHasher = passwordHasher;
            _tokenService   = tokenService;
            if (!_usersDb.Users.Any())
            {
                _usersDb.Users.Add(new User
                {
                    Username = "******",
                    Password = _passwordHasher.GenerateIdentityV3Hash("Password")
                });
                _usersDb.Users.Add(new User
                {
                    Username = "******",
                    Password = _passwordHasher.GenerateIdentityV3Hash("Password")
                });

                _usersDb.SaveChanges();
            }
            if (!_appsDb.Users.Any())
            {
                _appsDb.Users.Add(new AppUser
                {
                    client_id = "clientid",
                    appSecret = _passwordHasher.GenerateIdentityV3Hash("secret")
                });
                _appsDb.SaveChanges();
            }
        }
        public ActionResult SignUp(Users user)
        {
            if (db.Users.FirstOrDefault(x => x.Email == user.Email) != null)
            {
                ModelState.AddModelError("Email", "Email already exist");
            }

            if (db.Users.FirstOrDefault(x => x.Name == user.Name) != null)
            {
                ModelState.AddModelError("Username", "Username already exist");
            }

            if (ModelState.IsValid)
            {
                var hashPassword = Crypto.HashPassword(user.Password);

                user.Password        = hashPassword;
                user.ConfirmPassword = hashPassword;

                db.Users.Add(user);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(user));
        }
Ejemplo n.º 4
0
        public AccountController(UsersDb usersDb, IPasswordHasher passwordHasher, ITokenService tokenService)
        {
            _usersDb        = usersDb;
            _passwordHasher = passwordHasher;
            _tokenService   = tokenService;
            if (!_usersDb.Users.Any())
            {
                _usersDb.Users.Add(new User
                {
                    Username = "******",
                    Password = _passwordHasher.GenerateIdentityV3Hash("Password")
                });
                _usersDb.Users.Add(new User
                {
                    Username = "******",
                    Password = _passwordHasher.GenerateIdentityV3Hash("Password")
                });

                _usersDb.SaveChanges();
            }
        }