Ejemplo n.º 1
0
        public ActionResult Login(CLoginViewModel login)
        {
            if (string.IsNullOrEmpty(login.txtAccount) ||
                string.IsNullOrEmpty(login.txtPassword)
                )
            {
                return(View());
            }

            //帳密驗證
            CMember cust = ((new CMemberFactory()).authenticated(
                                login.txtAccount, login.txtPassword));

            if (cust != null)
            {
                //存進Session
                Session[CDictionary.SK_LOGINED_USER] = cust;
                Session["member"] = login.txtAccount;

                //重新導向到 首頁
                return(RedirectToAction("xxx", "CV"));
                //return RedirectToAction("Home");
            }
            return(View());
        }
Ejemplo n.º 2
0
        public JsonResult checklogin([FromBody] CLoginViewModel p)
        {
            //CLoginViewModel p = new CLoginViewModel();
            string Data = "";

            if (p.txtAccount != null && p.txtPassword != null)
            {
                using (dbMyCompanyContext db = new dbMyCompanyContext())
                {
                    var user = db.TUsers.Where(a => a.CEmployeeId == int.Parse(p.txtAccount)).FirstOrDefault();

                    if (user != null)
                    {
                        if (user.CPassWord != p.txtPassword)
                        {
                            Data = "密碼錯誤";
                        }
                        else if (user.CAccountEnable == 0 && user.COnBoardStatusId == 1)
                        {
                            Data = "帳號未啟用";
                        }
                        else if (user.COnBoardStatusId == 2)
                        {
                            Data = "員工已離職";
                        }
                    }
                    else
                    {
                        Data = "無此帳號";
                    }
                }
            }
            return(Json(Data));
        }
Ejemplo n.º 3
0
        public IActionResult Login(CLoginViewModel p)
        {
            string Account = Request.Form["txtAccount"].ToString();
            string Psd     = Request.Form["txtPassword"].ToString();

            if (string.IsNullOrEmpty(Account) || string.IsNullOrEmpty(Psd))
            {
                return(PartialView());
            }
            else
            {
                TUser user = (new dbMyCompanyContext()).TUsers.FirstOrDefault(c =>
                                                                              c.CEmployeeId.Equals(Int32.Parse(p.txtAccount)) && c.CPassWord.Equals(p.txtPassword));

                if (user != null)
                {
                    if (user.COnBoardStatusId == 1 && user.CAccountEnable == 1)
                    {
                        HttpContext.Session.SetObject <TUser>(CDictionary.Current_User, user);
                        HttpContext.Session.SetString("Today", DateTime.Now.ToString("yyyy/MM/dd"));
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERNAME, user.CEmployeeName);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERDEPARTMENT, ((eDepartment)user.CDepartmentId).ToString());
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERDEPARTMENTID, (user.CDepartmentId).ToString());
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERJOBTITLE, ((eJobTitle)user.CJobTitleId).ToString());
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERJOBTITLEID, user.CJobTitleId.ToString());
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERID, user.CEmployeeId.ToString());
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERENNAME, user.CEmployeeEnglishName);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_PASSWORD, user.CPassWord);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_OBD, (user.COnBoardDay).ToString());
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_BBD, (user.CByeByeDay).ToString());
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_GENDER, user.CGender);
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_EMAIL, user.CEmail);
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_ADDRESS, user.CAddress);
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_SUPERVISOR, (user.CSupervisor).ToString());
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_BRD, (user.CBirthday).ToString());
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_PHONE, user.CPhone);
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_EMERGENCY_PER, user.CEmergencyPerson);
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_EMERGENCY_CONT, user.CEmergencyContact);

                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_OB_STATUS, ((eOnBoard)user.COnBoardStatusId).ToString());
                        //HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_ACC_ENABLE, ((eAccount)user.CAccountEnable).ToString());
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }

            return(PartialView());
        }
Ejemplo n.º 4
0
        public ActionResult Login(CLoginViewModel model, string ReturnUrl = "")
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            //string base64Password = Convert.ToBase64String(Encoding.UTF8.GetBytes(Password));

            using (CDbContext dc = new CDbContext())
            {
                var userlist = dc.users.ToList <CUser>();

                var user = dc.users.Where(
                    a => a.userid.Equals(model.Username) && a.pwd.Equals(model.Password)).FirstOrDefault();
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(user.userid, model.RememberMe);
                    //FormsIdentity id=HttpContext.User.

                    //FormsAuthenticationTicket ticket = new FormsAuthenticationTicket()



                    if (Url.IsLocalUrl(ReturnUrl))
                    {
                        return(Redirect(ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "無此帳號或密碼錯誤");
                    return(View(model));
                }
            }

            ModelState.Remove("Password");
            //var userstore=new users
            return(View());
        }
Ejemplo n.º 5
0
 public IActionResult AccEnable(CLoginViewModel p, TUserViewModel _user)
 {
     if (p.txtAccount != null && p.txtPassword != null)
     {
         if (_user != null)
         {
             TUser u = db.TUsers.FirstOrDefault(u => u.CEmployeeId == int.Parse(p.txtAccount) && u.CPassWord == p.txtPassword);
             if (u != null)
             {
                 u.CAccountEnable = 1;
                 db.SaveChanges();
             }
             else
             {
                 ViewBag.Message = "錯誤的帳號或密碼";
             }
         }
     }
     return(RedirectToAction("Login"));
 }
        public ActionResult LogIn(CLoginViewModel login)
        {
            string userId = login.fUserId;
            string password = login.fPassword;

            var member = db.tMember
                .Where(m => m.fUserId == userId && m.fPassword == password)
                .FirstOrDefault();

            var Using = db.tMember
                .Where(u => u.fUserId == userId && u.fPassword == password && u.fUsing == "N")
                .FirstOrDefault();

            if (Using != null)
            {
                ViewBag.Message2 = "帳號已被停權";
                return View();
            }

            //if (member == null)
            //{
            //    ViewBag.Message = "請重新輸入帳號密碼";
            //    return View();
            //}
            //else 
            //{
            //    if (Using != null) 
            //    {
            //        ViewBag.Message2 = "帳號已被停權";
            //        return View();
            //    }
            //}
            Session[CDictionary.SK_LOGINED_USER] = member;

            return RedirectToAction("Index");
        }
Ejemplo n.º 7
0
 public Login()
 {
     InitializeComponent();
     DataContext = new CLoginViewModel(CUserSupplier.Create());
 }
Ejemplo n.º 8
0
        public JsonResult loginCheck([FromBody] CLoginViewModel loginMember)
        {
            擺腹BuyFoodContext db = new 擺腹BuyFoodContext();
            var check信箱         = from n in db.TMembers
                                  select n.CEmail;

            if (check信箱.Any(n => n == loginMember.CEmail) == true)
            {
                TMember freezeCheck = (from n in db.TMembers
                                       where n.CEmail == loginMember.CEmail
                                       select n).FirstOrDefault();

                var check密碼 = (from n in db.TMembers
                               where n.CEmail == loginMember.CEmail
                               select n).FirstOrDefault();

                SHA1 sha1 = SHA1.Create();

                string pwd解密 = shareFun.GetHash(sha1, loginMember.CPassword);

                if (check密碼.CFreezeCount >= 4)
                {
                    return(Json("memberFrozed"));
                }
                else if (check密碼.CPassword == pwd解密)
                {
                    if (check密碼.COpenMember == 0)
                    {
                        return(Json("notOpen"));
                    }
                    else
                    {
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERNAME, check密碼.CName);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERPHOTO, check密碼.CPicture);
                        HttpContext.Session.SetString(CDictionary.CURRENT_LOGINED_USERID, check密碼.CMemberId.ToString());

                        freezeCheck.CFreezeCount = 0;
                        db.SaveChanges();

                        return(Json("loginSuccess"));
                    }
                }
                else
                {
                    if (check密碼.CFreezeCount == 3)
                    {
                        freezeCheck.CFreezeCount += 1;
                        db.SaveChanges();
                        return(Json("FrozeComplete"));
                    }
                    else
                    {
                        freezeCheck.CFreezeCount += 1;
                        db.SaveChanges();
                        return(Json("FrozeCountPlus"));
                    }
                }
            }
            else
            {
                return(Json("noEmail"));
            }
        }