コード例 #1
0
        public ActionResult Index(Login login, Captcha captcha)
        {
            //Validate on "hack".
            if (login == null)
            {
                if (Request.IsAjaxRequest())
                {
                    return Content("Incorrect user name or password.");
                }

            }

            //Check captcha result.
            if (captcha == null || Session["Captcha"] == null || Session["Captcha"].ToString() != captcha.CaptchaResult)
            {
                ModelState.AddModelError("Captcha", "Wrong value of sum, please try again.");
                //display error and generate a new captcha
                return View();
            }

            //Check user details.
            if (LoginHelpers.IsExist(login))
            {

                //try to get user data from the DB.
                var user = LoginHelpers.GetUser(login);

                //If this user is exist, then marked the user as authenticated.
                if (user != null && user.Client != null)
                {
                    string userName = String.Format("{0} {1}", user.Client.FirstName, user.Client.LastName);
                    FormsAuthentication.SetAuthCookie(userName, true);
                    Session.Add("user", user);

                    if (string.IsNullOrEmpty(user.Client.Keyword))
                    {
                        return View("SetKeyword", user.Client);
                    }
                    if (user.Group.GroupName.Equals("Admin"))
                    {
                        Session.Add("Role", "Admin");
                        return RedirectToAction("Index", "Admin");
                    }

                    return RedirectToAction("Index", "Account");
                }
            }
            else
            {
                ViewBag.Message = "Login name or password is incorrect!";
                ModelState.AddModelError("login", "Login name or password is incorrect!");
            }

            if (Request.IsAjaxRequest())
            {
                return Content("Incorrect user name or password. Please try again.");
            }

            return View();
        }
コード例 #2
0
        public ActionResult Login(Login login)
        {
            TryValidateModel(login);


            if (ModelState.IsValid)
            {
                Customer customer = BussinessManager.validatecustomer(login.Username.Trim(), login.Password.Trim());
                if (customer != null)
                {
                    this.Session.Add("user", customer);
                    this.Session.Add("books", BussinessManager.Getbook());
                    string query = Request.QueryString["to"];

                    if (query != null)
                    {
                        //TODO: Primary Basis
                        return(this.RedirectToRoute(Request.Url.Authority + query));
                    }
                    else
                    {
                        return(this.RedirectToAction("Index", "Posts"));
                    }
                }
            }



            return(View());
        }
コード例 #3
0
        public ActionResult Index(Login login, Captcha captcha)
        {
            //Validate on "hack".
            if (login == null)
            {
                ViewBag.Message = "Incorrect login name or password. Access denied.";
                if (Request.IsAjaxRequest())
                {
                    return Content("Incorrect user name or password.");
                }
            }

            //Check user details.
            if (LoginHelpers.IsExist(login))
            {

                //try to get user data from the DB.
                var user = LoginHelpers.GetUser(login);

                //If this user is exist, then marked the user as authenticated.
                if (user != null && user.Client != null && user.Group != null && user.Group.GroupName.Equals("Admin"))
                {
                    string userName = String.Format("{0} {1}", user.Client.FirstName, user.Client.LastName);
                    FormsAuthentication.SetAuthCookie(userName, false);
                    Session.Add("Role", "Admin");

                    return RedirectToAction("Index", "AdminAccount");

                }
            }
            else
                ViewBag.Message = "Incorrect login name or password. Access denied.";

            if (Request.IsAjaxRequest())
            {
                return Content("Incorrect user name or password. Please try again.");
            }

            return View();
        }
コード例 #4
0
 public ActionResult Login(Login login)
 {
     TryUpdateModel(login);
     try
     {
         if (db.LoginSubmit(login.Username, login.Password,
                      "adminUsername",
                      "adminPassword",
                      "tblcompanyadmin") > 0)
         {
             FormsAuthentication.SetAuthCookie(login.Username, login.Remember);
             return RedirectToAction("Index", "Approval");
         }
         ViewBag.ErrorMessage = "Invalid Username/Password";
         return View();
     }
     catch (Exception ex)
     {
         ViewBag.ErrorMessage = ex.Message;
         return View();
     }
 }
コード例 #5
0
        public Models.UserInfo FetchUserInfo(Models.Login info)
        {
            Models.UserInfo BALinfo = new Models.UserInfo();
            using (var db = new Expense_ManagerEntities())
            {
                bool isvalid = db.user_info.Any(x => x.email == info.email && x.password == info.password);
                if (isvalid)
                {
                    DAL.user_info DALinfo = db.user_info.Where(x => x.email == info.email && x.password == info.password).FirstOrDefault();
                    BALinfo.id               = DALinfo.id;
                    BALinfo.firstname        = DALinfo.firstname;
                    BALinfo.lastname         = DALinfo.lastname;
                    BALinfo.email            = DALinfo.email;
                    BALinfo.password         = DALinfo.password;
                    BALinfo.confirm_password = DALinfo.confirm_password;
                    BALinfo.month_start_date = DALinfo.month_start_date;
                    BALinfo.profile_pic_path = DALinfo.profile_pic_path;

                    //var userdetail2 = from s in db.user_info where s.email == info.email && s.password == info.password select s;
                }
            }
            return(BALinfo);
        }
コード例 #6
0
        public int IsUserExistWithUsernamePass(Models.Login info)
        {
            int result = 1;

            using (var db = new Expense_ManagerEntities())
            {
                bool isUserexist   = db.user_info.Any(x => x.email == info.email);
                bool isCorrectPass = false;
                if (isUserexist)
                {
                    isCorrectPass = db.user_info.Any(x => x.email == info.email && x.password == info.password);
                    if (!isCorrectPass)
                    {
                        result = -1;
                    }
                }
                else
                {
                    result = -2;
                }
            }
            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Check exiting of the user by login model.
        /// </summary>
        /// <param name="login">User login model.</param>
        /// <returns>true if exist.</returns>
        public static bool IsExist(Login login)
        {
            if (login == null || string.IsNullOrEmpty(login.UserName))
            {
                return false;
            }

            return IsExist(login.UserName);
        }
コード例 #8
0
        /// <summary>
        /// Returns bank user by user login.
        /// </summary>
        /// <param name="login">User login.</param>
        /// <returns>Specified user or null if the user is not exists in the DB.</returns>
        public static BankUser GetUser(Login login)
        {
            if (login == null)
            {
                return null;
            }

            return GetUser(login.UserName, login.Password);
        }