Пример #1
0
        public ActionResult Login(LoginRegisterVM model, string sReturnURL)
        {
            //flags that you are using Login Action
            model.IsActionLogin();

            if (ModelState.IsValid)
            {
                var login = new Login();
                var dbase = new tblStudent();
                //login.Username = model.loginvm.Username;
                //login.Password = model.loginvm.Password;
                using (studentDBase studentDBase = new studentDBase())
                {
                    if (studentDBase.tblStudents.Any(x => x.User__Name == model.loginvm.Username) && studentDBase.tblStudents.Any(x => x.Password == model.loginvm.Password))
                    {
                        return(RedirectToAction("Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Incorrect Username or Password ");
                    }
                    return(View(model));
                }
            }
            else
            {
                return(View(model));
            }
        }
Пример #2
0
        public ActionResult Register(LoginRegisterVM model, string sReturnURL)
        {
            //flags that you are using Register Action
            model.IsActionRegister();

            if (ModelState.IsValid)
            {
                var tblStud = new tblStudent();
                //RegisterVM registerVM = new RegisterVM();
                using (studentDBase studentDBase = new studentDBase())
                {
                    if (studentDBase.tblStudents.Any(x => x.User__Name == model.registervm.Username))
                    {
                        ModelState.AddModelError("", " Username already exists! ");
                        return(View(model));
                    }
                    tblStud.Country    = model.registervm.Country;
                    tblStud.Email      = model.registervm.Email;
                    tblStud.First_Name = model.registervm.Name;
                    tblStud.Last_Name  = model.registervm.Surname;
                    tblStud.Password   = model.registervm.Password;
                    tblStud.User__Name = model.registervm.Username;

                    studentDBase.tblStudents.Add(tblStud);
                    studentDBase.SaveChanges();
                    return(RedirectToAction("Home"));
                }
            }
            else
            {
                return(View(model));
            }
        }
Пример #3
0
        public async Task <ActionResult> Register(LoginRegisterVM model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Register.UserName, Email = model.Register.Email, height = model.Register.height, PhoneNumber = model.Register.Mobile
                };
                var result = await UserManager.CreateAsync(user, model.Register.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Пример #4
0
        public async Task <ActionResult> Login(LoginRegisterVM model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            var result = await SignInManager.PasswordSignInAsync(model.Login.Email, model.Login.Password, model.Login.RememberMe, shouldLockout : false);

            switch (result)
            {
            case SignInStatus.Success:
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.Login.RememberMe }));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
        }
Пример #5
0
        public ActionResult Registration(LoginRegisterVM vm, HttpPostedFileBase file)
        {
            User user = vm.RegisterToUser();

            if (user == null)
            {
                TempData["ErrorMessage"] = "Registration form not valid";
                return(RedirectToAction("Index"));
            }

            string mappningstringtophoto = "~/Content/images/";

            if (file == null)
            {
                mappningstringtophoto = mappningstringtophoto + "user_default.jpg";
            }
            else
            {
                var fileName = Path.GetFileName(file.FileName);
                var path     = Path.Combine(Server.MapPath("~/Content/images/"), fileName);
                mappningstringtophoto = mappningstringtophoto + fileName;
                file.SaveAs(path);
            }
            try
            {
                var dbUser = user.GetByEmail(user.Email, db);

                if (dbUser == null)
                {
                    //Create a hashkey
                    var HashKey = Encrypt.GeneratePassword(10);

                    //Create a encrypted password with the hashkey
                    var password = Encrypt.EncodePassword(user.Password, HashKey);

                    user.Password = password;
                    user.HashCode = HashKey;

                    user.ImageUrl = mappningstringtophoto;
                    user.RoleId   = 2;

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

                    TempData["Message"] = "Account Created";

                    return(RedirectToAction("Index", "Profile"));
                }

                TempData["ErrorMessage"] = "Email already in use!";

                return(RedirectToAction("Index"));
            }
            catch (DbEntityValidationException e)
            {
                ViewBag.ErrorMessage = "Database and models do not match";
                return(RedirectToAction("Index"));
            }
        }
Пример #6
0
        public ActionResult Login(LoginRegisterVM vm)
        {
            User user = vm.LoginToUser();

            try
            {
                if (user != null)
                {
                    //Email must be unique for this to work.
                    var dbUser = user.GetByEmail(user.Email, db);

                    //Get the Encrypted Password
                    string encodedPassword = Encrypt.EncodePassword(user.Password, dbUser.HashCode);

                    //Check if the encrypted input matches what is stored in
                    var userExist = user.CheckPassword(encodedPassword, db);

                    if (userExist != null)
                    {
                        //Start Session
                        Session["User"]     = dbUser;
                        TempData["Message"] = "Login Successful";

                        return(RedirectToAction("Index", "Profile"));
                    }

                    TempData["ErrorMessage"] = "Invallid User Name or Password";
                    return(RedirectToAction("Index"));
                }


                TempData["ErrorMessage"] = "Invallid User Name or Password";
                return(RedirectToAction("Index"));
            }
            catch
            {
                TempData["ErrorMessage"] = "Email does not exist";
                return(RedirectToAction("Index"));
            }
        }
Пример #7
0
 public ActionResult LoginRegister(LoginRegisterVM model, string sReturnURL)
 {
     return(View(model));
 }