Esempio n. 1
0
        public ActionResult Themmoi_capnhat_Account(string act, string mataikhoan, ManageUserViewModel model)
        {
            if (!IsLogged())
            {
                return(BackToLogin());
            }
            if (act == "create")
            {
                LoginServices    service     = new LoginServices();
                TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                TaiKhoanModels   modeltk     = new TaiKhoanModels();
                // Lay du lieu employee
                var user = service.GetLoginData(new M_TaiKhoan()
                {
                    tendangnhap = model.tendangnhap,
                    xoa         = CST_Common.CST_NOT_DELETE,
                    kichhoat    = CST_Common.CST_ACTIVE
                });
                if (user == null)
                {
                    TaiKhoanModels param = new TaiKhoanModels();
                    param.hoten       = model.hoten;
                    param.tendangnhap = model.tendangnhap;
                    if (model.matkhau != null)
                    {
                        param.matkhau = EncDec.EncodePassword(model.matkhau);
                    }
                    param.thudientu    = model.thudientu;
                    param.maphongban   = model.maphongban;
                    param.machucdanh   = model.machucdanh;
                    param.chucdanhkpi  = model.machucdanh.ToString();
                    param.macongtruong = model.macongtruong;
                    param.loaicuochop  = model.loaicuochop;

                    if (model.machucdanh.ToString().Trim() == "2" || model.machucdanh.ToString().Trim() == "4")
                    {
                        param.grouptk = "2";
                    }
                    else if (model.machucdanh.ToString() == "9")
                    {
                        param.grouptk = "1";
                    }
                    else
                    {
                        param.grouptk = "0";
                    }

                    param.madonvi = 1;
                    int nguoitao = int.Parse(Session["userid"].ToString());
                    TaiKhoanServices taikhoan = new TaiKhoanServices();
                    bool             kq       = taikhoan.AddUser(param, nguoitao);
                }
                else
                {
                    return(RedirectToAction("Manage", "Account"));
                }
            }
            else if (act == "update")
            {
                TaiKhoanModels param = new TaiKhoanModels();
                param.hoten       = model.hoten;
                param.tendangnhap = model.tendangnhap;

                if (model.machucdanh.ToString().Trim() == "2" || model.machucdanh.ToString().Trim() == "4")
                {
                    param.grouptk = "2";
                }
                else if (model.machucdanh.ToString() == "9")
                {
                    param.grouptk = "1";
                }
                else
                {
                    param.grouptk = "0";
                }


                if (model.kichhoat == "on")
                {
                    param.kichhoat = "1";
                }
                else
                {
                    param.kichhoat = "";
                }

                if (model.matkhau != null)
                {
                    param.matkhau = EncDec.EncodePassword(model.matkhau);
                }
                param.mataikhoan = mataikhoan;
                param.thudientu  = model.thudientu;
                param.maphongban = model.maphongban;
                //param.machucdanh = model.machucdanh;
                param.chucdanhkpi = model.machucdanh.ToString();
                param.madonvi     = 1;

                param.macongtruong = model.macongtruong;
                param.loaicuochop  = model.loaicuochop;

                int nguoihieuchinh        = int.Parse(Session["userid"].ToString());
                TaiKhoanServices taikhoan = new TaiKhoanServices();
                bool             kq       = taikhoan.UpdateUser(param, nguoihieuchinh);
            }
            else if (act == "del")
            {
                //ChucDanhModels param = new ChucDanhModels();
                //FunctionXML function = new FunctionXML(Functions.MapPath("~/Xml/Config/encryptionkeyEncodeLink.config"));
                //param.machucdanh = int.Parse(AES.DecryptText(mataikhoan, function.ReadXMLGetKeyEncrypt()));

                int nguoihieuchinh        = int.Parse(Session["userid"].ToString());
                TaiKhoanServices taikhoan = new TaiKhoanServices();

                bool result = taikhoan.DeletedUser(mataikhoan, nguoihieuchinh);
            }
            return(RedirectToAction("Manage", "Account"));
        }
Esempio n. 2
0
        public ActionResult Login(TaiKhoanModels model, string returnUrl, string captcha)
        {
            _logger.Start("Login");
            bool bCaptcha = false;

            ViewBag.isNhapCaptcha = false;
            LoginServices service = new LoginServices();

            try
            {
                //neu so lan user dang nhap vuot qua gioi han se bi lock
                if (Session[strSessionLoginFail] == null)
                {
                    Session[strSessionLoginFail] = 0;
                }
                int loginFail = (int)Session[strSessionLoginFail];
                if (!string.IsNullOrEmpty(captcha) && !string.IsNullOrWhiteSpace(captcha))
                {
                    if (captcha == Session[strSessionCaptcha].ToString())
                    {
                        bCaptcha = true;
                    }
                }
                if (loginFail < RICONS.Core.Constants.CST_Common.CST_Lock || bCaptcha)
                {
                    #region kiem tra user login tren he thong AD admin
                    bool   validAD          = false;
                    string matkhaudangnnhap = model.matkhau;
                    string tendangnhap      = model.tendangnhap.Trim().Split('@')[0].ToLower();
                    var    passWordDecrypt  = EncDec.DecryptStringAES(model.matkhau);
                    try
                    {
                        using (PrincipalContext context = new PrincipalContext(ContextType.Domain, "newtecons.vn", tendangnhap, passWordDecrypt))
                        {
                            validAD = context.ValidateCredentials(tendangnhap, passWordDecrypt);
                            UserPrincipal user_ad = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, tendangnhap);
                            if (validAD)
                            {
                                #region
                                var user = service.GetLoginData(new M_TaiKhoan()
                                {
                                    tendangnhap = tendangnhap,
                                    xoa         = CST_Common.CST_NOT_DELETE,
                                    kichhoat    = CST_Common.CST_ACTIVE
                                });
                                TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                                TaiKhoanModels   modeltk     = new TaiKhoanModels();
                                // Lay du lieu employee
                                //var dlemployee = serTaiKhoan.GetDataEmployee(tendangnhap);
                                if (user == null)
                                {
                                    #region
                                    //if (dlemployee != null)
                                    //{
                                    //    modeltk.manhansu = dlemployee.manhansu;
                                    //    modeltk.hoten = dlemployee.hoten;
                                    //    modeltk.machucdanh = dlemployee.machucdanh;
                                    //    modeltk.tenchucdanh = dlemployee.tenchucdanh;
                                    //    modeltk.maphongban = dlemployee.maphongban;

                                    //    if (dlemployee.phongban_congtruong.ToString().ToLower() == "false")
                                    //        modeltk.phongban_congtruong = "0";
                                    //    else modeltk.phongban_congtruong = "1";

                                    //}
                                    modeltk.tendangnhap = tendangnhap;
                                    model.madonvi       = 1;
                                    modeltk.thudientu   = user_ad.EmailAddress;
                                    modeltk.chucdanhkpi = "1";
                                    bool kq = serTaiKhoan.AddUser(modeltk, 0);
                                    user = service.GetLoginData(new M_TaiKhoan()
                                    {
                                        tendangnhap = tendangnhap,
                                        xoa         = CST_Common.CST_NOT_DELETE,
                                        kichhoat    = CST_Common.CST_ACTIVE
                                    });
                                    #endregion
                                }
                                //else if (dlemployee != null)
                                //{
                                //    //Cập nhật manhansu,machucdanh,maphongban
                                //    user.manhansu = dlemployee.manhansu;
                                //    user.maphongban = dlemployee.maphongban;
                                //    user.machucdanh = dlemployee.machucdanh;
                                //    user.tenchucdanh = dlemployee.tenchucdanh;
                                //    user.hoten = dlemployee.hoten;
                                //    user.sodienthoai = dlemployee.sodienthoai;
                                //    user.thudientu = user_ad.EmailAddress;
                                //    user.ngaysinh = dlemployee.ngaysinh;
                                //    user.chucdanhkpi = user.chucdanhkpi;
                                //    if(dlemployee.phongban_congtruong.ToString().ToLower()=="false")
                                //        user.phongban_congtruong = "0";
                                //    else user.phongban_congtruong = "1";

                                //    if (user.chucdanhkpi.Trim() == "" || user.chucdanhkpi == null)
                                //        user.chucdanhkpi = "1";
                                //    bool kqcapnhat = serTaiKhoan.Updatemanhansu(user.mataikhoan, user.manhansu, user.machucdanh.ToString(), user.maphongban, user.hoten, user.chucdanhkpi, user.phongban_congtruong);
                                //}
                                var lstPhongBanDonVis = serTaiKhoan.SelectPhongBanDonVi(new M_TaiKhoan()
                                {
                                    mataikhoan = user.mataikhoan
                                });
                                user.phongBanDonVis = lstPhongBanDonVis;
                                AddSession(user);
                                UpdateLoginState(tendangnhap, false, loginFail);
                                //chuyen trang
                                _logger.End("Login");
                                return(RedirectToAction("Index", "WeedMeeting"));

                                //return RedirectToLocal(returnUrl);
                                #endregion
                            }
                            else if (!validAD)
                            {
                                #region
                                var user = service.GetLoginData(new M_TaiKhoan()
                                {
                                    tendangnhap = model.tendangnhap,
                                    matkhau     = EncDec.EncodePassword(passWordDecrypt),
                                    xoa         = CST_Common.CST_NOT_DELETE,
                                    kichhoat    = CST_Common.CST_ACTIVE
                                });
                                if (user != null)
                                {
                                    TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                                    var lstPhongBanDonVis        = serTaiKhoan.SelectPhongBanDonVi(new M_TaiKhoan()
                                    {
                                        mataikhoan = user.mataikhoan
                                    });
                                    user.phongBanDonVis = lstPhongBanDonVis;
                                    AddSession(user);
                                    UpdateLoginState(model.tendangnhap, false, loginFail);
                                    _logger.End("Login");
                                    return(RedirectToAction("Index", "WeedMeeting"));
                                }
                                else
                                {
                                    try
                                    {
                                        UpdateLoginState(model.tendangnhap, true, loginFail);
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.Error(ex);
                                    }
                                }
                                #endregion
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        validAD = false;
                        _logger.Info(ex);
                    }
                    #endregion

                    #region kiem tra user login local

                    if (!validAD)
                    {
                        var user = service.GetLoginData(new M_TaiKhoan()
                        {
                            tendangnhap = model.tendangnhap,
                            matkhau     = EncDec.EncodePassword(passWordDecrypt),
                            xoa         = CST_Common.CST_NOT_DELETE,
                            kichhoat    = CST_Common.CST_ACTIVE
                        });
                        if (user != null)
                        {
                            TaiKhoanServices serTaiKhoan = new TaiKhoanServices();
                            var lstPhongBanDonVis        = serTaiKhoan.SelectPhongBanDonVi(new M_TaiKhoan()
                            {
                                mataikhoan = user.mataikhoan
                            });
                            user.phongBanDonVis = lstPhongBanDonVis;
                            AddSession(user);
                            UpdateLoginState(model.tendangnhap, false, loginFail);
                            _logger.End("Login");
                            return(RedirectToAction("Index", "WeedMeeting"));
                        }
                        else
                        {
                            try
                            {
                                UpdateLoginState(model.tendangnhap, true, loginFail);
                            }
                            catch (Exception ex)
                            {
                                _logger.Error(ex);
                            }
                        }
                    }
                    #endregion
                }
                else
                {
                    ViewBag.isNhapCaptcha = true;
                    UpdateLoginState(model.tendangnhap, true, loginFail);
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                _logger.End("CheckLogin");
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }