public ActionResult LoginUser(User model)
        {
            model.Password = CommonConstant.Encrypt(model.Password);
            bool check = new AccountDAO().checkAccount(model.Username, model.Password);

            if (check)
            {
                var roleID = db.Users.Where(a => a.Username == model.Username).FirstOrDefault().UserRoleID;
                Session["roleID"] = roleID;
                if (check && ((int)Session["roleID"] == 2))
                {
                    Session["UserName"] = model.Username;
                    if (model.ImageURL != null)
                    {
                        Session["imageUser"] = model.ImageURL;
                    }
                    else
                    {
                        Session["imageUser"] = "******";
                    }
                    var dao     = db.Users.Where(x => x.Username == model.Username).Select(x => x.UserID).ToList();
                    var name    = db.Users.Where(a => a.Username == model.Username && a.Password == model.Password).FirstOrDefault().Username;
                    var blockID = db.Users.Where(a => a.Username == model.Username).FirstOrDefault().isActivated;
                    Session["UserID"]    = dao[0].ToString();
                    Session["userHello"] = name;
                    Session["blockID"]   = blockID;
                    return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
                }
            }
            return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult ExecuteLogin(User model)
        {
            //model.Password = CommonConstant.HashPassword(model.Password);
            model.Password = CommonConstant.Encrypt(model.Password);
            bool check = new AccountDAO().checkAccount(model.Username, model.Password);

            if (check)
            {
                var roleID = db.Users.Where(a => a.Username == model.Username).FirstOrDefault().UserRoleID;
                Session["roleID"] = roleID;
                if (check && ((int)Session["roleID"] == 1))
                {
                    Session["UserName"] = model.Username;
                    if (model.ImageURL != null)
                    {
                        Session["imageUser"] = model.ImageURL;
                    }
                    else
                    {
                        Session["imageUser"] = "******";
                    }
                    var dao = db.Users.Where(x => x.Username == model.Username).Select(x => x.UserID).ToList();
                    Session["UserID"] = dao[0].ToString();
                    return(Json(new { status = true }));
                }
                else
                {
                    return(Json(new { status = false }));
                }
            }
            return(Json(new { status = false }));
        }
Exemplo n.º 3
0
 public ActionResult Register(User model)
 {
     if (ModelState.IsValid)
     {
         using (BSDBContext db = new BSDBContext())
         {
             var user = db.Users.FirstOrDefault(p => p.Username == model.Username);
             if (user == null)
             {
                 model.UserRoleID  = 1;
                 model.isActivated = true;
                 model.Password    = CommonConstant.Encrypt(model.Password);
                 db.Users.Add(model);
                 db.SaveChanges();
             }
             else
             {
                 ViewBag.Message = "Tài khoản " + model.Username + " đã tồn tại";
                 return(View());
             }
         }
         ModelState.Clear();
         ViewBag.Message = "Đăng ký thành công cho tài khoản " + model.Username;
     }
     return(RedirectToAction("Login"));
 }
Exemplo n.º 4
0
 public ActionResult Login(User ac)
 {
     ac.Password = CommonConstant.Encrypt(ac.Password);
     using (BSDBContext db = new BSDBContext())
     {
         var result = db.Users.Where(p => p.Username == ac.Username && p.Password == ac.Password).Count();
         if (result == 0)
         {
             ModelState.AddModelError("", "Tài khoản không tồn tại hoặc Tên đăng nhập, mật khấu bị sai.");
         }
         else
         {
             var userID  = db.Users.Where(a => a.Username == ac.Username).FirstOrDefault().UserID;
             var name    = db.Users.Where(a => a.Username == ac.Username && a.Password == ac.Password).FirstOrDefault().Username;
             var blockID = db.Users.Where(a => a.Username == ac.Username).FirstOrDefault().isActivated;
             var roleID  = db.Users.Where(a => a.Username == ac.Username).FirstOrDefault().UserRoleID;
             Session["userHello"] = name;
             Session["userName"]  = ac.Username;
             Session["UserID"]    = userID;
             Session["blockID"]   = blockID;
             Session["roleID"]    = roleID;
             return(Redirect(Request.Url != null ? Request.Url.ToString() : Url.Action("Index")));
         }
     }
     return(View());
 }
Exemplo n.º 5
0
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new {
                client_id     = ConfigurationManager.AppSettings["FbAppId"],
                client_secret = ConfigurationManager.AppSettings["FbAppSecret"],
                redirect_uri  = RedirectUri.AbsoluteUri,
                code          = code
            });

            var accessToken = result.access_token;
            var expires     = result.expires;

            Session[CommonConstant.AccessToken] = accessToken;

            if (!string.IsNullOrEmpty(accessToken))
            {
                fb.AccessToken = accessToken;
                dynamic me       = fb.Get("me?fields=id,name,email,first_name,birthday,last_name,gender,address");
                string  Avatar   = string.Format("https://graph.facebook.com/{0}/picture", me.id);
                string  email    = me.email;
                string  id       = me.id;
                string  fullName = me.first_name + me.last_name;
                string  birth    = me.birthday;

                //Thêm tài khoản vào bảng User
                var user = new User();
                user.Username    = me.id;
                user.FullName    = fullName;
                user.Birthday    = DateTime.Now;
                user.Email       = email;
                user.ImageURL    = Avatar;
                user.UserRoleID  = CommonConstant.userRoleNormal;
                user.isActivated = CommonConstant.isActived;
                user.Password    = CommonConstant.Encrypt("123456");
                user.Address     = me.address;

                var rslt = new AccountDAO().InsertForFacebook(user);
                if (rslt != null)
                {
                    var userID  = db.Users.Where(a => a.Username == user.Username).FirstOrDefault().UserID;
                    var name    = db.Users.Where(a => a.Username == user.Username && a.Password == user.Password).FirstOrDefault().Username;
                    var blockID = db.Users.Where(a => a.Username == user.Username).FirstOrDefault().isActivated;
                    var roleID  = db.Users.Where(a => a.Username == user.Username).FirstOrDefault().UserRoleID;
                    Session[CommonConstant.userHello] = name;
                    Session[CommonConstant.userName]  = user.Username;
                    Session[CommonConstant.UserID]    = userID;
                    Session[CommonConstant.blockID]   = blockID;
                    Session[CommonConstant.roleID]    = roleID;
                }
            }
            if (Session[CommonConstant.userHello] != null)
            {
                return(RedirectToAction("EditProfile", "ProfileUser", new { userName = Session[CommonConstant.userName] }));
            }
            else
            {
                return(Redirect("/"));
            }
        }
Exemplo n.º 6
0
 public ActionResult Register(User account)
 {
     if (account.Username == null || account.Password == null)
     {
         return(View());
     }
     if (ModelState.IsValid)
     {
         using (BSDBContext db = new BSDBContext())
         {
             var user = db.Users.FirstOrDefault(p => p.Username == account.Username);
             if (user == null)
             {
                 account.UserRoleID  = 2;
                 account.isActivated = true;
                 account.Password    = CommonConstant.Encrypt(account.Password);
                 account.Birthday    = DateTime.Now;
                 db.Users.Add(account);
                 db.SaveChanges();
             }
             else
             {
                 ViewBag.Message = "UserName already exists" + account.Username;
                 return(View());
             }
         }
         ModelState.Clear();
         ViewBag.Message = "Successfully Registered Mr. " + account.Username;
     }
     return(RedirectToAction("Index"));
 }
Exemplo n.º 7
0
        /// <summary>
        /// แสดงหน้าโครงการจากระบบ E-Budget เพื่อให้เลือกนำเข้ามาระบบ Risk และสามารถ Link ที่นำเข้ามาแล้วไปยังหน้า Project Risk ได้เลย
        /// </summary>
        /// <returns>View</returns>
        public ActionResult ProjectEBudget()
        {
            ViewBag.TabMenu = "2";
            int riskLimit = 5;

            //ViewBag.AppName = CommonConstant.ApplicationName(Request);
            ViewBag.Menus = MenuSession = new List <Models.Menu>
            {
                new Models.Menu {
                    Name = "หน้าแรก", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/Home"), IdTab = "tab0",
                },
                new Models.Menu {
                    Name = "โครงการที่ยังไม่สมบูรณ์", Url = CommonConstant.GetApplicationUrl(Request, "/UserPage/ProjectRisk_Incomplete"), IdTab = "ta1b0",
                },
                new Models.Menu {
                    Name = "โครงการทั้งหมด", Url = "", IdTab = "tab10",
                },
                new Models.Menu {
                    Name = "ติดต่อเรา", Url = CommonConstant.GetApplicationUrl(Request, "/Contacts"), IdTab = "tab10"
                },
            };

            Dictionary <string, List <string> > projectEBudget = new Dictionary <string, List <string> >();

            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("1")), new List <string>()
            {
                "12003-001", "โครงการทดลองนะจ๊ะ 1", "10,000,000.00", "1"
            });
            riskLimit--;
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("2")), new List <string>()
            {
                "12003-002", "โครงการทดลองนะจ๊ะ 2", "500,000,000.00", "0"
            });
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("3")), new List <string>()
            {
                "12003-003", "โครงการทดลองนะจ๊ะ 3", "400,000,000.00", "0"
            });
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("4")), new List <string>()
            {
                "12003-004", "โครงการทดลองนะจ๊ะ 4", "200,000,000.00", "1"
            });
            riskLimit--;
            projectEBudget.Add(CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("5")), new List <string>()
            {
                "12003-005", "โครงการทดลองนะจ๊ะ 5", "300,000,000.00", "0"
            });
            ViewBag.ProjectEBudget = projectEBudget;
            ViewBag.RiskLimit      = riskLimit;

            return(View());
        }
Exemplo n.º 8
0
        public JsonResult LoginAjax(string user_name, string pass)
        {
            pass = CommonConstant.Encrypt(pass);
            using (BSDBContext db = new BSDBContext())
            {
                var result = db.Users.Where(p => p.Username == user_name && p.Password == pass).Count();
                if (result == 0)
                {
                    object jsondata = new LoginClass
                    {
                        SessionRole     = null,
                        SessionUsername = null
                    };
                    return(Json(jsondata, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    var roleID = db.Users.Where(a => a.Username == user_name).FirstOrDefault().UserRoleID;
                    if (roleID == 1)
                    {
                        object jsondata = new LoginClass
                        {
                            SessionRole     = null,
                            SessionUsername = null
                        };
                        return(Json(jsondata, JsonRequestBehavior.AllowGet));
                    }
                    else
                    {
                        var userID  = db.Users.Where(a => a.Username == user_name).FirstOrDefault().UserID;
                        var name    = db.Users.Where(a => a.Username == user_name && a.Password == pass).FirstOrDefault().Username;
                        var blockID = db.Users.Where(a => a.Username == user_name).FirstOrDefault().isActivated;
                        Session["userHello"] = name;
                        Session["userName"]  = user_name;
                        Session["UserID"]    = userID;
                        Session["blockID"]   = blockID;
                        Session["roleID"]    = roleID;

                        object jsondata = new LoginClass
                        {
                            SessionRole     = Session["roleID"].ToString(),
                            SessionBlockID  = Convert.ToBoolean(Session["blockID"]),
                            SessionUsername = Session["userName"].ToString()
                        };
                        return(Json(jsondata, JsonRequestBehavior.AllowGet));
                    }
                }
            }
        }
Exemplo n.º 9
0
        public ActionResult ChangePassword(string newPass)
        {
            int userID = Convert.ToInt32(Session["UserID"].ToString());
            var model  = db.Users.Find(userID);

            //newPass = CommonConstant.HashPassword(newPass);
            newPass = CommonConstant.Encrypt(newPass);
            int check = 1;

            try
            {
                model.Password = newPass;
                db.SaveChanges();
            }
            catch (Exception ex)
            {
                check = -1;
            }
            return(Json(check, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 10
0
        public string GetProjectRisk_IncompleteYear(string year)
        {
            for (int i = 0; i < 5000000; i++)
            {
                Console.WriteLine(i);
            }

            try
            {
                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 1);

                IList <Dictionary <string, object> > projectData = new List <Dictionary <string, object> >();
                if (year == "2559")
                {
                    projectData.Add(new Dictionary <string, object>()
                    {
                        { "ProjectID", CommonConstant.RemovePlusAndSpaceSymolFromBase64(CommonConstant.Encrypt("1")) },
                        { "ProjectName", "โครงการนำร่องผลิตน้ำมันเพื่อใช้ภายในประเทศจากแหล่งทรัพยากรธรรมชาติของชาติ" },
                        { "ProjectCategory", "" },
                        { "ProjectFund", "1,000,000,000" },
                        { "ProjectLastUpdate", "29/05/2558" },
                    });
                }

                jsonResult.Add("data", projectData);
                jsonResult.Add("recordCount", 1);

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
            catch (Exception exc)
            {
                Dictionary <string, object> jsonResult = new Dictionary <string, object>();
                jsonResult.Add("result", 0);
                jsonResult.Add("message", exc.ToString());

                return(new JavaScriptSerializer().Serialize(jsonResult));
            }
        }