Exemple #1
0
        public ActionResult UserLogin(Core.Login objLogin)
        {
            int Count = 0;

            if (objlogin.checkUser(objLogin)) // Calls the Login class checkUser() for existence of the user in the database.
            {
                // FormsAuthentication.SetAuthCookie(objLogin.username, false);

                Session["UserName"] = objLogin.username;

                Session["UserId"] = Convert.ToInt64(objLogin.userid);

                if (Session["UserName"] != null && Session["UserId"] != null)
                {
                    Count = 1;
                }
            }
            else
            {
                // return Content("<script language='javascript' type='text/javascript'>alert('Thanks for Feedback!');</script>");
                TempData["AlertMessage"] = "Invalid Username or Password";
                //return the same view with message "Invalid Username or Password"
            }
            return(new JsonResult {
                Data = Count, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Exemple #2
0
 public bool checkUser(Core.Login objLogin)
 {
     //bool flag = false;
     try
     {
         using (NpgsqlConnection con = new NpgsqlConnection(NPGSqlHelper.SQLConnString))
         {
             if (con.State == ConnectionState.Closed)
             {
                 con.Open();
             }
             using (NpgsqlCommand cmd = new NpgsqlCommand("select userid from tabuserinfo where username='******' and userpassword='******'", con))
             {
                 objLogin.userid = Convert.ToInt64(cmd.ExecuteScalar());
             }
             if (con.State == ConnectionState.Open)
             {
                 con.Close();
                 con.ClearPool();
             }
         }
         if (objLogin.userid != 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (System.Exception ex)
     {
         // EventLogger.WriteToErrorLog(ex, "Login");
         // npgdr.Dispose();
         throw;
     }
     finally
     {
     }
 }