예제 #1
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (model.Domain == "SUPPERADMIN")
                {
                    using (var dbConn = Helpers.OrmliteConnection.openConn())
                    {
                        var existUser = dbConn.SingleOrDefault <User>("ma_nguoi_dung ={0} and mat_khau ={1} and trang_thai = 'true'", model.UserName, Helpers.GetMd5Hash.Generate(model.Password));
                        if (existUser != null)
                        {
                            SetupFormsAuthTicket(model.UserName, model.RememberMe);
                            return(RedirectToAction("Index", "admin/Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
                        }
                        //var passadmin = System.Configuration.ConfigurationManager.AppSettings["passAdmin"].ToString().Trim();
                        //if (model.Password == passadmin)
                        //{
                        //    //Code giành cho đăng nhập bằng pass admin
                        //    var userpasadmin = dbConn.SingleOrDefault<Users>("UserName = {0} ", model.UserName);
                        //    if (userpasadmin != null)
                        //    {
                        //        SetupFormsAuthTicket(model.UserName, model.RememberMe);
                        //        var employeeinfoa = dbConn.FirstOrDefault<EmployeeInfo>("UserName ={0}", userpasadmin.UserName);
                        //        return RedirectToLocal(returnUrl);
                        //    }
                        //    else
                        //        ModelState.AddModelError("", "Invalid username or password.");
                        //}

                        //var user = dbConn.SingleOrDefault<Users>("UserName = {0} AND Password = {1} AND Active = 1", model.UserName, Helpers.GetMd5Hash.Generate(model.Password));
                        //if (user != null)
                        //{
                        //    //code đăng nhập bình thường
                        //    SetupFormsAuthTicket(model.UserName, model.RememberMe);
                        //    var employeeinfo = dbConn.FirstOrDefault<EmployeeInfo>("UserName ={0}", user.UserName);
                        //    return RedirectToLocal(returnUrl);
                        //}
                        //else
                        //    ModelState.AddModelError("", "Invalid username or password.");
                    }
                }
                else
                {
                    try
                    {
                        using (var client = new HttpClient())
                        {
                            // New code:
                            var apiserver = System.Configuration.ConfigurationManager.AppSettings["apiServer"].ToString().Trim();
                            var userNameE = HelperEncrypt.Encrypt(HelperEncrypt.GetHashKey(HelperEncrypt.passSalt), model.UserName);
                            var passWordE = HelperEncrypt.Encrypt(HelperEncrypt.GetHashKey(HelperEncrypt.passSalt), model.Password);
                            var domainE   = HelperEncrypt.Encrypt(HelperEncrypt.GetHashKey(HelperEncrypt.passSalt), model.Domain);
                            var apiUrl    = apiserver + "//api//Authentication//checkAuthenticate?domain=" + domainE + "&userName="******"&passWord="******"\"", "")) == "success" ? true : false;
                            if (!isSuccessAuthenticate)
                            {
                                ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
                                return(View(model));
                            }
                            using (var dbConn = Helpers.OrmliteConnection.openConn())
                            {
                                var existUser = dbConn.SingleOrDefault <User>("ma_nguoi_dung ={0} and trang_thai = 'true'", model.UserName);
                                if (existUser != null)
                                {
                                    SetupFormsAuthTicket(model.UserName, model.RememberMe);
                                    return(RedirectToLocal(returnUrl));
                                }
                                else
                                {
                                    ModelState.AddModelError("", "Tên đăng nhập hoặc mật khẩu không đúng.");
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("", "Không thể kết nối đến domain");
                    }
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        private void btOK_Click(object sender, EventArgs e)
        {
            if (radioGroupTrial.SelectedIndex == 1)
            {
                //- Check selected license file complete?
                // If complete, to check enter license key.
                // If not, show warning message box screen 1022.

                // - Check enter licensed key completed?
                // If complete, to check validate license file and license key.
                // If not, show warning message box screen 1023.

                // - Check validates license file and license key?
                // If valid, show information message box screen 3018, load data from license file to database and show screen 2801-2.
                // If not valid, show warning message box screen 1024.

                if (textEditFile.EditValue == null)
                {
                    utilClass.showPopupMessegeBox(this, getLanguage("_msg_1022"), this.Text);
                    return;
                }

                if (textEditKey1.EditValue != null && textEditKey2.EditValue != null && textEditKey3.EditValue != null && textEditKey4.EditValue != null)
                {
                    string TextKey = textEditKey1.EditValue.ToString() + "-" + textEditKey2.EditValue.ToString() + "-" + textEditKey3.EditValue.ToString() + "-" + textEditKey4.EditValue.ToString();
                    if (TextKey == MainForm.LicObj.LicenseKey)
                    {
                        BusinessLogicBridge.DataStore.updateLicenceKey(MainForm.LicObj.LicenseKey);

                        DataTable GeneralPath = BusinessLogicBridge.DataStore.getGeneralConfig();

                        string dataPath = MainForm.CombinePaths(AppDomain.CurrentDomain.BaseDirectory, "Licence");

                        if (Directory.Exists(dataPath) == false)
                        {
                            Directory.CreateDirectory(dataPath);
                        }

                        try
                        {
                            string descnationfile = Path.Combine(dataPath, "regkey.lic");
                            System.IO.File.Copy(textEditFile.EditValue.ToString(), descnationfile, true);
                            objMEATHLicense LicObj = new objMEATHLicense();
                            LicObj = MainForm.readLicense(descnationfile);
                            BusinessLogicBridge.DataStore.updateADCSerial(LicObj.ADCSN1, LicObj.ADCSN2, LicObj.ADCSN3, LicObj.ADCSN4, LicObj.ADCSN5);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message.ToString());
                        }

                        utilClass.showPopupMessegeBox(this, getLanguage("_msg_3018"), this.Text, "info");

                        MainForm.TrialVersion = false;
                        MainForm.HaveLicence  = true;
                        this.DialogResult     = DialogResult.OK;
                    }
                    else
                    {
                        utilClass.showPopupMessegeBox(this, getLanguage("_msg_1024"), this.Text);
                        this.DialogResult = DialogResult.Cancel;
                    }
                }
                else
                {
                    utilClass.showPopupMessegeBox(this, getLanguage("_msg_1023"), this.Text);
                    return;
                }
            }
            else
            {
                // Trial Version
                MainForm.TrialVersion = true;

                string s = BusinessLogicBridge.DataStore.getCheckinCounter();

                if (s == "")
                {
                    s = HelperEncrypt.Encrypt(s, MainForm.hashKey);

                    // Update Counter Checkin
                    BusinessLogicBridge.DataStore.updateCounterCheckin(s);
                }

                this.DialogResult = DialogResult.Ignore;
            }
        }