Example #1
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext.HttpContext.Session[ComConst.User] == null)
            {
                if (string.IsNullOrEmpty(autologinName))
                {
                    filterContext.HttpContext.Response.Write("<script>if(parent!=null) parent.window.location.href='/?t'; else window.location.href='/?t';</script>");
                    filterContext.HttpContext.Response.End();
                    return;
                }
                else
                {
                    User user = UserService.GetInstance().GetUserByName(autologinName);
                    UserUtil.login(user);

                    //记录登录记录
                    string ip = WebUtil.getClientIp(filterContext.HttpContext.Request);
                    LoginRecordService.GetInstance().Save(user.id, autologinName, ip, 0);

                    base.OnActionExecuting(filterContext);
                }
            }
            else
            {
                base.OnActionExecuting(filterContext);
            }
        }
Example #2
0
        /// <summary>
        /// 功能:示例电站
        /// </summary>
        /// <returns></returns>
        public ActionResult ExamplePlant()
        {
            string zone  = Request.QueryString.ToString();
            float  fzone = 0;

            float.TryParse(zone, out fzone);
            User userinfo = UserService.GetInstance().GetUserByName(UserUtil.demousername);

            UserUtil.login(userinfo);
            LoginRecordService.GetInstance().Save(userinfo.id, userinfo.username, WebUtil.getClientIp(Request), fzone);
            return(RedirectToAction("allplants", "user"));
        }
Example #3
0
        public ActionResult Reg(User user)
        {
            int localZont = 0;

            int.TryParse(Request.Form["localZone"], out localZont);
            //创建语言服务
            LanguageService languageservice = LanguageService.GetInstance();
            //获取所有语言信息
            IList <Language> languages = languageservice.GetList();

            ViewData["languages"] = languages;
            User regUser = userService.GetUserByName(user.username);

            if (regUser == null)
            {
                int uid = 0;
                user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
                uid           = userService.save(user);
                //注册用户默认管理员权限
                UserRoleService.GetInstance().Insert(new UserRole()
                {
                    userId = uid, roleId = 3
                });

                TempData[ComConst.User] = user;
                UserUtil.ResetLogin(user);
                //记录登录记录
                string ip = WebUtil.getClientIp(Request);
                LoginRecordService.GetInstance().Save(user.id, user.username, ip, localZont);

                return(RedirectToAction("success", "auth"));
            }
            else
            {
                ModelState.AddModelError("UserName", Resources.SunResource.REG_USERNAME_ERROR_INFO);
                return(View());
            }
        }
        public ActionResult Save(User user)
        {
            if (user.id > 0)
            {
                UserService userService = UserService.GetInstance();
                int         languageId  = userService.GetLanguageIdById(UserUtil.getCurUser().id);
                //创建语言服务
                LanguageService languageservice = LanguageService.GetInstance();
                //获取所有语言信息
                Language         language  = languageservice.GetNameByLanguageId(languageId);
                IList <Language> languages = languageservice.GetList();
                ViewData["lang"]      = language;
                ViewData["languages"] = languages;
                UserService userservice = UserService.GetInstance();
                ViewData["langs"] = LanguageService.GetInstance().GetList();
                base.GetLanguage();

                IList <CommonInfo> currencies = CommonInfoService.GetInstance().GetList(new CommonInfo()
                {
                    pid = CommonInfo.Currency
                });
                IList <SelectListItem> items = new List <SelectListItem>();
                foreach (CommonInfo currency in currencies)
                {
                    items.Add(new SelectListItem()
                    {
                        Text = string.Format("{0}:{1}", currency.code, currency.name), Value = currency.code
                    });
                }


                ViewData["currencies"] = items;
                return(RedirectToAction("addplant", "newregister"));
            }
            else
            {
                int localZont = 0;
                int.TryParse(Request.Form["localZone"], out localZont);
                //创建语言服务
                LanguageService languageservice = LanguageService.GetInstance();
                //获取所有语言信息
                IList <Language> languages = languageservice.GetList();
                ViewData["languages"] = languages;
                User regUser = UserService.GetInstance().GetUserByName(user.username);
                if (regUser == null)
                {
                    int uid = 0;
                    user.password = EncryptUtil.EncryptDES(user.password, EncryptUtil.defaultKey);
                    uid           = UserService.GetInstance().save(user);
                    //注册用户默认管理员权限
                    UserRoleService.GetInstance().Insert(new UserRole()
                    {
                        userId = uid, roleId = 3
                    });

                    TempData[ComConst.User] = user;
                    UserUtil.ResetLogin(user);
                    //记录登录记录
                    string ip = WebUtil.getClientIp(Request);
                    LoginRecordService.GetInstance().Save(user.id, user.username, ip, localZont);

                    return(RedirectToAction("addplant", "newregister"));
                }
                else
                {
                    ModelState.AddModelError("UserName", Resources.SunResource.REG_USERNAME_ERROR_INFO);
                    return(View("register"));
                }
            }
        }
Example #5
0
        public ActionResult Index(User user, bool autoLogin, string localZone, string validatecode)
        {
            float lzone = 0;

            try
            {
                float.TryParse(localZone, out lzone);
            }
            catch (Exception ee)
            {
                Console.WriteLine("转换时区异常:" + ee.Message);
                try
                {
                    LogUtil.error("登录转换时区异常: " + user == null ? "" : user.username + ee.Message);
                }
                catch (Exception ee2)
                {
                    Console.WriteLine("写日志文件异常:" + ee2.Message);
                }
            }

            //验证码验证提示
            try
            {
                if (validatecode != null && ValidateCodeUtil.Validated(validatecode) == false)
                {
                    ModelState.AddModelError("Error", "验证码输入错误!");
                    System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                    loadIndexData();
                    return(View(user));
                }
            }
            catch (Exception ee)
            {
                Console.WriteLine("验证码验证异常:" + ee.Message);
                ModelState.AddModelError("Error", "验证码验证错误!");
                System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                loadIndexData();
                return(View(user));
            }

            //验证用户名输入项
            if (user == null || user.username == null)
            {
                ModelState.AddModelError("Error", Resources.SunResource.HOME_INDEX_USERNAME_REQUIRED);
                System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                loadIndexData();
                return(View(user));
            }

            //首先认为是电站用户登录
            User loginUser = userService.GetUserByName(user.username);

            if (loginUser == null || !loginUser.depassword.Equals(user.password))
            {
                //判断是否管理员
                Manager manager = managerService.GetUserByName(user.username);
                if (manager != null)
                {
                    if (manager.depassword.Equals(user.password))
                    {
                        manager = managerService.GetManagerByLocked(user.username);
                        if (manager != null)
                        {
                            if (autoLogin)
                            {
                                SetCookie(user.username, manager.password);
                            }
                            base.mlogin(manager);

                            //这里admin 默认所有权限
                            if (manager.username.Equals("admin"))
                            {
                                return(RedirectToAction(@"users", "admin"));
                            }
                            if (manager.roles == null || manager.roles.Count == 0)
                            {
                                return(Content("access denied"));
                            }
                            try
                            {
                                foreach (AdminUserRole auserRole in manager.roles)
                                {
                                    if (auserRole.role != null)
                                    {
                                        IList <AdminControllerAction> acas  = AdminControllerActionServices.GetInstance().GetList();
                                        IList <AdminControllerAction> allow = AdminRole.AllowActionsList(acas, auserRole.role.actions);
                                        foreach (AdminControllerAction aca in allow)
                                        {
                                            if (aca.isAutoRedirect)
                                            {
                                                return(RedirectToAction(@aca.actionName, aca.controllerName));
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception ee3) { }
                        }
                        else
                        {
                            System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                            ModelState.AddModelError("Error", Resources.SunResource.MANAGER_LOGIN_LOCKED);
                            loadIndexData();
                            return(View(user));
                        }
                    }
                }
                else
                {
                    System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
                    ModelState.AddModelError("Error", Resources.SunResource.HOME_INDEX_VALIDATED);
                    loadIndexData();
                    return(View(user));
                }
            }
            else
            {
                if (loginUser.depassword.Equals(user.password))
                {
                    //注释  不根据用户语言设置默认语言
                    //CultureInfo cultureInfo = null;
                    //if (loginUser.Language == null)
                    //    loginUser.Language = new Language() { codename = "en-us" };
                    //cultureInfo = new CultureInfo(loginUser.Language.codename);
                    //Session["Culture"] = cultureInfo;
                    //Thread.CurrentThread.CurrentCulture = cultureInfo;
                    //Session["display"] = loginUser.Language.name;

                    if (autoLogin)
                    {
                        SetCookie(user.username, loginUser.depassword);
                    }
                    UserUtil.login(loginUser);

                    //记录登录记录
                    try
                    {
                        string ip = WebUtil.getClientIp(Request);
                        LoginRecordService.GetInstance().Save(loginUser.id, loginUser.username, ip, lzone);
                    }
                    catch (Exception ee)
                    {
                        Console.WriteLine("记录ip错误:" + ee.Message);
                    }



                    //如果是非门户用户进入
                    if (!loginUser.isBigCustomer)
                    {
                        //判断是否完成注册的三个步骤
                        return(adjustUserPosition(loginUser));
                    }
                    else
                    {
                        IList <Plant> protalPlants = loginUser.assignedPortalPlants;
                        ///判断是否有电站
                        if (protalPlants.Count < 1)
                        {
                            ModelState.AddModelError("Error", "您的账户中无电站,暂时不能登录");
                            return(View(user));
                        }
                        Session[ComConst.portalautoLogin] = null;
                        if (protalPlants.Count == 1)
                        {
                            return(RedirectToAction(protalPlants[0].isVirtualPlant ? "virtual" : "plant", "portal", new { @id = protalPlants[0].id }));
                        }
                        else
                        {
                            return(RedirectToAction("index", "portal"));
                        }
                    }
                }
            }

            if (user.username.Equals("manuser") && user.depassword.Equals("sungrow2011"))
            {
                Session["collectorAddedEnable"] = true;
                return(RedirectToAction("admin", "admin"));
            }


            //登录失败
            ModelState.AddModelError("Error", Resources.SunResource.HOME_INDEX_VALIDATED);
            System.Web.HttpContext.Current.Response.Cookies["a_login"].Expires = DateTime.Now.AddDays(-1);
            loadIndexData();
            return(View(user));
        }