Beginner here.
I can't seen to get my login validation to work. It is supposed to show that the login was succesful, or that the user information was invalid, but nothing happens.
Can anyone spot the problem?
The form:
- <div class="container" style="margin-top: 10%">
- <div class="row">
- <div class="col-md-4 col-md-offset-4 alert alert-info">
- <h3 class="text-center">Loginh3>
- <form id="loginForm">
- <div id="msg"><ul style="color:red;">Invalid Email or Passwordul>div>
- <div class="form-group">
- <div class="input-group">
- <span class="input-group-addon">
- <i class="glyphicon glyphicon-envelope">i>
- span>
- <input class="form-control" type="email" name="email" id="email" placeholder="Email" />
- div>
- div>
- <div class="form-group">
- <div class="input-group">
- <span class="input-group-addon">
- <i class="glyphicon glyphicon-lock">i>
- span>
- <input class="form-control" type="Password" name="pwd" id="pwd" placeholder="Password" />
- div>
- div>
- form>
- <div class="form-group">
- <button class="btn btn-info form-control" type="submit" onclick="Login()">
- <i class="glyphicon glyphicon-log-in">i>
- button>
- div>
- <div class="form-group">
- <a style="float:left">Forgot Password?a>
- <a style="float:right;cursor:pointer" onclick="SignUp()">Sign Upa>
- div>
- div>
- div>
- div>
The script:
- $("#msg").hide();
- var login = function () {
- var data = $("#loginForm").serialize();
- $.ajax({
- type: "post",
- url: "/Register/CheckValidUser",
- data: data,
- success: function (result) {
- if (result == "Fail") {
- $("#loginForm")[0].reset();
- $("#msg").show();
- }
- else {
- window.location.href = "/Register/AfterLogin";
- $("#msg").hide();
- }
- }
- })
- }
RegisterController:
- public JsonResult CheckValidUser(customer model)
- {
- string result = "fail";
- var DataItem = db.customer.Where(x => x.email == model.email && x.pwd == model.pwd).SingleOrDefault();
- if (DataItem != null)
- {
- Session["customerID"] = DataItem.customerID.ToString();
- Session["email"] = DataItem.email.ToString();
- result = "Success";
- }
- return Json(result, JsonRequestBehavior.AllowGet);
- }
- public ActionResult AfterLogin()
- {
- if (Session["customerID"] != null)
- {
- return View();
- }
- else
- {
- return RedirectToAction("Index");
- }
- }
- public ActionResult Logout()
- {
- Session.Clear();
- Session.Abandon();
- return RedirectToAction("Index");
- }
- }
- }
- @{
- ViewBag.Title = "AfterLogin";
- }
AfterLogin
- @if (Session["costumerID"] != null)
- {
- }
Laxmidhar SahooPosted Nov 20, 2018, 6:55 AM
mounika honeyPosted Nov 20, 2018, 5:40 AM