Пример #1
0
        // GET: WEBUSERS
        public async Task<ActionResult> Index()
        {
            RegViewModel vModel = new RegViewModel();
            
            var branchSql = await (from a in db.M_BRANCH select a).ToListAsync();
            var regionSql = await (from b in db.M_REGION select b).ToListAsync();
            
            //vModel._list = new Dictionary<string, string>();
            //vModel._listRegion = new Dictionary<string, string>();
            GlobalVar.BranchList = new Dictionary<string, string>();
            GlobalVar.RegionList = new Dictionary<string, string>();
            foreach (var r in branchSql)
            {
                GlobalVar.BranchList.Add(r.BRANCH_CODE, r.BRANCH_NAME);                 
            }

            foreach (var rw in regionSql)
            {
                GlobalVar.RegionList.Add(rw.CODE, rw.REGION_NAME);                
            }
            vModel._list = GlobalVar.BranchList;
            vModel._listRegion = GlobalVar.RegionList;
            vModel.isError = 0;
            return View(vModel);
        }
Пример #2
0
        public async Task<ActionResult> Index(string uname, string password)
        {
            if (string.IsNullOrEmpty(uname) || string.IsNullOrEmpty(password))
            {
                ViewBag.errMessage = "Invalid Credentials";
                return View();
            }

            myEncrypt.lscryptoKey = "ITDept6953069";
            string tempPass = myEncrypt.psEncrypt(password, myElement).ToString();
            var userSQL = await (from a in db.TBL_WEBUSERS where (a.USERNAME == uname && a.PASSWORD == tempPass && a.ACTIVE == true && a.COMP == "MLY") || (a.USERNAME == uname && a.SHA_PASSWORD == password && a.ACTIVE == true && a.COMP == "MLY") select a).ToListAsync();

            if (userSQL.Count > 0)
            {
                if (!string.IsNullOrEmpty(userSQL[0].PASSWORD))
                {
                    if (userSQL[0].PASSWORD == password)
                    {
                        Session["UName"] = userSQL[0].USERNAME;
                        Session["LoggedUserId"] = userSQL[0].USER_ID;
                        Session["LName"] = userSQL[0].FIRSTNAME;
                        Session["LoggedRegion"] = userSQL[0].REGION;
                        Session["BranchCode"] = userSQL[0].BRANCH_CODE;
                        Session["UserType"] = userSQL[0].USER_TYPE;
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    if (userSQL[0].SHA_PASSWORD == password)
                    {
                        Session["UName"] = userSQL[0].USERNAME;
                        Session["LoggedUserId"] = userSQL[0].USER_ID;
                        Session["LName"] = userSQL[0].FIRSTNAME;
                        Session["LoggedRegion"] = userSQL[0].REGION;
                        Session["BranchCode"] = userSQL[0].BRANCH_CODE;
                        Session["UserType"] = userSQL[0].USER_TYPE;
                        return RedirectToAction("Index", "Home");
                    }
                }
                
                Session["UName"] = userSQL[0].USERNAME;
                Session["LoggedUserId"] = userSQL[0].USER_ID;
                Session["LName"] = userSQL[0].FIRSTNAME;
                Session["LoggedRegion"] = userSQL[0].REGION;
                Session["BranchCode"] = userSQL[0].BRANCH_CODE;
                Session["UserType"] = userSQL[0].USER_TYPE;
                return RedirectToAction("Index", "Home");
            }
            else
            {
                RegViewModel vmod = new RegViewModel();             

              
                vmod._list = GlobalVar.BranchList;
                vmod._listRegion = GlobalVar.RegionList;
                vmod.isError = 2;
                vmod.errMessage = "Invalid Credentials";
                ViewBag.errMessage = "Invalid Credentials";
                return View(vmod);
            }
        }
Пример #3
0
        public async Task<ActionResult> Create(RegViewModel tblUser) //[Bind(Include = "lastname,firstname,middlename,address,username,contactno,email,region,city")
        //string lname, string fname, string mname, string nostreet, string city, string region, string uname, string password, string cpassword, string email        
        {
            RegViewModel vmodel = new RegViewModel();
            TBL_WEBUSERS tbl = new TBL_WEBUSERS();
            if (ModelState.IsValid)
            {
                TBL_WEBUSERS ifExist = await db.TBL_WEBUSERS.FirstOrDefaultAsync(m => m.USERNAME == tblUser.username);



                if (!(ifExist == null))
                {
                    vmodel._list = GlobalVar.BranchList;
                    vmodel._listRegion = GlobalVar.RegionList;
                    vmodel.isError = 2;
                    vmodel.errMessage = "Username already taken. Kindly choose different username.";
                    return View(vmodel);

                }

                ifExist = await db.TBL_WEBUSERS.FirstOrDefaultAsync(m => m.EMAIL == tblUser.email);
                if (!(ifExist == null))
                {
                    vmodel._list = GlobalVar.BranchList;
                    vmodel._listRegion = GlobalVar.RegionList;
                    vmodel.isError = 2;
                    vmodel.errMessage = "Email already registered. Please choose different email address or use password recovery system.";
                    return View(vmodel);
                }


                tbl.LASTNAME = tblUser.lastname;
                tbl.FIRSTNAME = tblUser.firstname;
                tbl.MIDDLENAME = tblUser.middlename;
                tbl.MAILING_ADDRESS = tblUser.address;
                tbl.CITY = tblUser.city;
                tbl.COMP = "MLY";
                tbl.REGION = tblUser.region;                
                tbl.USERNAME = tblUser.username;
                tbl.CONTACT_NUMBER = tblUser.contactno;
                //tbl.PASSWORD = password;
                tbl.USER_CODE = Yfunction.generateSerial(9, "ITDept6953069");
                tbl.SHA_PASSWORD = Yfunction.generateRandomString(12, "ITDept6953069");
                if (!string.IsNullOrEmpty(tblUser.email))
                {
                    tbl.EMAIL = tblUser.email;
                    //shaPass = Yfunction.generateRandomString(12, myElement);                    
                }

                DateTime now = DateTime.Now;
                tbl.DATE_REGISTERED = now;
                //tbl.BRANCH_CODE = tblUser.bCode;
                tbl.USER_TYPE = "CLIENT";
                tbl.BRANCH_CODE = "HardCoded Branch Code";
                db.TBL_WEBUSERS.Add(tbl);
                await db.SaveChangesAsync();
                string tempname = tbl.FIRSTNAME + " " + tbl.LASTNAME;               
                string _bod = string.Format("Dear Sir/Madam {0}, <BR/><BR/> Your account is now registered to RCTPL Web App. Thank you. <BR/> Please click on the link to activate your registration: <a href=\"https://" + WebConfigurationManager.AppSettings["ServerIP"] + "/WEBUSERS/CompletingRegistration/{1}/{2}\">Activate Registration</a> <br/><br/>Username: {3} <br/>Password: {4} <br/><br/> Kindly replace your temporary password as soon as you login. <br/>Thank you!", tempname, tbl.USERNAME, tbl.SHA_PASSWORD, tbl.USERNAME, tbl.SHA_PASSWORD);
                sendEmail("RCTPL Web Registration", "Registration Confirmation", _bod, tblUser.email);
                vmodel._list = GlobalVar.BranchList;
                vmodel._listRegion = GlobalVar.RegionList;
                vmodel.isError = 1;
                return View(vmodel);
            }
            vmodel._list = GlobalVar.BranchList;
            vmodel._listRegion = GlobalVar.RegionList;
            vmodel.isError = 2;
            vmodel.errMessage = "Something went wrong. Please click Register again for details.";
            return View(vmodel);
        }
Пример #4
0
 // GET: Registration of new user
 public ActionResult Create()
 {
     RegViewModel vModel = new RegViewModel();
     vModel._list = GlobalVar.BranchList;
     vModel._listRegion = GlobalVar.RegionList;
     vModel.isError = 0;
     return View(vModel);
 }