예제 #1
0
        public ActionResult DangNhapTheoIdNguoiDung(string IdNguoiDung)
        {
            //TempData["returnUrl"] = Url.Action("Index", "NguoiDung");
            if (Session["UserToken"] == null)
            {
                return(Json(false));
            }
            var quyenTruyCap = XuLyPhanQuyen.KiemTraQuyenTruyCap(ChucNang.Ma.QuanLyTaiKhoan, QuyenHan.Ma.Xoa);

            if (quyenTruyCap == null || quyenTruyCap.KetQua < 0)
            {
                return(Json(false));
            }
            try
            {
                //Đọc thông tin tài khoản
                var input = new DangNhapTheoIdNguoiDungInput();
                input.IdNguoiDung = IdNguoiDung;
                var output = XuLyAPI.ApiJsonPost(APIUrl.NguoiDung.DangNhapTheoIdNguoiDung, input) as CommonOutput;
                Session.Clear();

                // Thành công
                var userLogin = JsonConvert.DeserializeObject <CommonNguoiDung.NguoiDungOutput.DangNhapTaiKhoan>(output.DuLieu.ToString());
                Session["UserToken"] = new CommonInput.UserToken {
                    TokenApi = userLogin.TokenApi, TokenNguoiDung = userLogin.TokenNguoiDung
                };
                Session["UserInfo"]     = userLogin;
                Session["MaDonVi"]      = userLogin.MaDonVi;
                Session["TenNguoiDung"] = userLogin.Ten;
                var input2     = new CommonTinh.TinhInput.DocThongTin();
                var outputTinh = XuLyAPI.ApiJsonPost(APIUrl.Tinh.DocThongTin, input2) as CommonOutput;
                if (outputTinh != null /*&& output.KetQua == 1*/)
                {
                    Session["Tinh"] = JsonConvert.DeserializeObject <CommonTinh.TinhOutput.ThongTinTinh>(outputTinh.DuLieu.ToString());
                }
                else
                {
                    Session["Tinh"] = null;
                }
                return(Json(true));
            }
            catch (Exception ex)
            {
                TempData["Error"] = ex.Message;
                return(Json(false));
            }
        }
예제 #2
0
        public ActionResult Login(CommonTaiKhoan.TaiKhoanInput.DangNhapInput model, string returnUrl)
        {
            try
            {
                if (string.IsNullOrEmpty(returnUrl))
                {
                    returnUrl = ChucNang.DuongDan.BangDieuKhien;
                }
                if (ModelState.IsValid)
                {
                    var matKhauGoc = model.MatKhau;
                    model.MatKhau = Utility.MD5(model.MatKhau);
                    var output = XuLyAPI.ApiJsonPost(APIUrl.TaiKhoan.DangNhap, model, false) as CommonOutput;
                    if (output == null)
                    {
                        throw new Exception("Lỗi Server");
                    }
                    if (output.KetQua != 1)
                    {
                        throw new Exception(output.ThongBao);
                    }
                    //Thành công
                    string url    = ConfigurationManager.AppSettings["urlSv"];
                    var    Zabbix = new ApiClient(url, model.TenTaiKhoan, matKhauGoc);
                    Zabbix.Login();
                    Session["Zabbix"] = Zabbix;
                    var userLogin = JsonConvert.DeserializeObject <CommonNguoiDung.NguoiDungOutput.DangNhapTaiKhoan>(output.DuLieu.ToString());
                    Session["UserToken"] = new CommonInput.UserToken {
                        TokenApi = userLogin.TokenApi, TokenNguoiDung = userLogin.TokenNguoiDung
                    };
                    Session["UserInfo"]     = userLogin;
                    Session["MaDonVi"]      = userLogin.MaDonVi;
                    Session["MaVaiTro"]     = userLogin.MaVaiTro;
                    Session["TenNguoiDung"] = userLogin.Ten;

                    var input      = new CommonTinh.TinhInput.DocThongTin();
                    var outputTinh = XuLyAPI.ApiJsonPost(APIUrl.Tinh.DocThongTin, input) as CommonOutput;
                    if (outputTinh != null /*&& output.KetQua == 1*/)
                    {
                        Session["Tinh"] = JsonConvert.DeserializeObject <CommonTinh.TinhOutput.ThongTinTinh>(outputTinh.DuLieu.ToString());
                    }
                    else
                    {
                        Session["Tinh"] = null;
                    }
                    try
                    {
                        returnUrl = TempData["returnUrl"].ToString();
                    }
                    catch (Exception ex)
                    {
                    }
                    return(RedirectToLocal(returnUrl));
                }
            }
            catch (Exception ex)
            {
                ViewBag.ThongBao = string.Format("Đăng nhập <b>{0}</b>!", ex.Message);
            }
            return(View());
        }