コード例 #1
0
ファイル: admin.aspx.cs プロジェクト: xkandj/proj-15-pks1.1
        /// <summary>从门户后台管理自动登录</summary>
        private bool AutoLogin(string returnUrl)
        {
            var token = this.Request.QueryString["token"];

            if (token.IsNullOrEmpty())
            {
                return(false);
            }
            var userId = this.Context.GetPortalMgmtUserId(token);

            if (userId.IsNullOrEmpty())
            {
                return(false);
            }
            var nUserId = 0;

            if (!int.TryParse(userId, out nUserId))
            {
                return(false);
            }
            var user = this.Context.GetPortalMgmtUser(nUserId);

            if (user == null)
            {
                return(false);
            }
            var admin   = Users.GetUserInfo(user.USERNAME);
            var context = this.Context.GetHttpContextWrapper();
            var config  = GeneralConfigs.GetConfig();

            if (admin == null)
            {
                var principal = new PKSPrincipal();
                var identity  = new PKSIdentity();
                identity.Name        = user.USERNAME;
                identity.Email       = user.EMAIL;
                identity.PhoneNumber = user.PHONENUMBER;
                principal.Identity   = identity;
                admin = context.CreateUser(config, principal, true);
            }
            else if (admin.Adminid != 1 || admin.Groupid != 1)
            {
                admin.Adminid  = 1;
                admin.Groupid  = 1;
                admin.Authtime = Utils.GetDateTime();
                AdminUsers.UpdateUserAllInfo(admin);
                //移除该用户的在线信息,使之重建在线表信息
                OnlineUsers.DeleteUserByUid(admin.Uid);
            }
            var adminGroup = AdminUserGroups.AdminGetUserGroupInfo(admin.Groupid);

            ForumUtils.WriteUserCookie(admin.Uid, ForumExtension.ExpireMinutes, config.Passwordkey);
            this.Context.AddAdminCookie(config, admin.Uid, admin.Password, admin.Secques, ForumExtension.ExpireMinutes);
            SoftInfo.LoadSoftInfo();
            AdminVistLogs.InsertLog(admin.Uid, admin.Username, admin.Groupid, adminGroup.Grouptitle, DNTRequest.GetIP(), "后台管理员登陆", "");
            return(true);
        }
コード例 #2
0
        public void VerifyLoginInf()
        {
            if (!Discuz.Forum.OnlineUsers.CheckUserVerifyCode(olid, DNTRequest.GetString("vcode")))
            {
                Response.Redirect("syslogin.aspx?result=3");
                return;
            }

            UserInfo userInfo = null;

            if (config.Passwordmode == 1)
            {
                userInfo = Users.GetUserInfo(Users.CheckDvBbsPassword(DNTRequest.GetString("username"), DNTRequest.GetString("password")));
            }
            else if (config.Passwordmode == 0)
            {
                userInfo = Users.GetUserInfo(Users.CheckPassword(DNTRequest.GetString("username"), Utils.MD5(DNTRequest.GetString("password")), false));
            }
            else//第三方加密验证模式
            {
                userInfo = Users.CheckThirdPartPassword(DNTRequest.GetString("username"), DNTRequest.GetString("password"), -1, null);
            }

            if (userInfo != null)
            {
                UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(userInfo.Groupid);

                if (usergroupinfo.Radminid == 1)
                {
                    ForumUtils.WriteUserCookie(userInfo.Uid, 1440, GeneralConfigs.GetConfig().Passwordkey);

                    //UserGroupInfo userGroupInfo = AdminUserGroups.AdminGetUserGroupInfo(userInfo.Groupid);

                    HttpCookie cookie = new HttpCookie("dntadmin");
                    cookie.Values["key"] = ForumUtils.SetCookiePassword(userInfo.Password + userInfo.Secques + userInfo.Uid, config.Passwordkey);
                    cookie.Expires       = DateTime.Now.AddMinutes(30);
                    HttpContext.Current.Response.AppendCookie(cookie);

                    AdminVistLogs.InsertLog(userInfo.Uid, userInfo.Username, userInfo.Groupid, usergroupinfo.Grouptitle, DNTRequest.GetIP(), "后台管理员登陆", "");

                    try
                    {
                        SoftInfo.LoadSoftInfo();
                    }
                    catch
                    {
                        Response.Write("<script type=\"text/javascript\">top.location.href='index.aspx';</script>");
                        Response.End();
                    }

                    //升级general.config文件
                    try
                    {
                        GeneralConfigs.Serialiaze(GeneralConfigs.GetConfig(), Server.MapPath("../config/general.config"));
                    }
                    catch { }

                    Response.Write("<script type=\"text/javascript\">top.location.href='index.aspx';</script>");
                    Response.End();
                }
                else
                {
                    Response.Redirect("syslogin.aspx?result=2");
                }
            }
            else
            {
                Response.Redirect("syslogin.aspx?result=1");
            }
        }
コード例 #3
0
        public void VerifyLoginInf()
        {
            if (!OnlineUsers.CheckUserVerifyCode(olid, DNTRequest.GetString("vcode")))
            {
                Response.Redirect("syslogin.aspx?result=3");
                return;
            }

            DataTable dt = new DataTable();

            if (config.Passwordmode == 1)
            {
                int uid = Discuz.Forum.Users.CheckDvBbsPassword(DNTRequest.GetString("username"), DNTRequest.GetString("password"));

                dt = DatabaseProvider.GetInstance().GetUserInfo(uid);
            }
            else
            {
                dt = DatabaseProvider.GetInstance().GetUserInfo(UserName.Text.Trim(), Utils.MD5(PassWord.Text.Trim()));
            }


            if (dt.Rows.Count > 0)
            {
                UserGroupInfo usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(Convert.ToInt32(dt.Rows[0]["groupid"].ToString()));

                if (usergroupinfo.Radminid == 1)
                {
                    ForumUtils.WriteUserCookie(Convert.ToInt32(dt.Rows[0]["uid"].ToString().Trim()), 1440, GeneralConfigs.GetConfig().Passwordkey);

                    int    userid      = Convert.ToInt32(dt.Rows[0]["uid"].ToString().Trim());
                    string username    = UserName.Text.Trim();
                    int    usergroupid = Convert.ToInt16(dt.Rows[0]["groupid"].ToString().Trim());
                    string secques     = dt.Rows[0]["secques"].ToString().Trim();
                    string ip          = DNTRequest.GetIP();

                    UserGroupInfo __usergroupinfo = AdminUserGroups.AdminGetUserGroupInfo(usergroupid);

                    string grouptitle = __usergroupinfo.Grouptitle;


                    HttpCookie cookie = new HttpCookie("dntadmin");
                    cookie.Values["key"] = ForumUtils.SetCookiePassword(Utils.MD5(PassWord.Text.Trim()) + secques + userid.ToString(), config.Passwordkey);
                    cookie.Expires       = DateTime.Now.AddMinutes(30);
                    HttpContext.Current.Response.AppendCookie(cookie);

                    AdminVistLogs.InsertLog(userid, username, usergroupid, grouptitle, ip, "后台管理员登陆", "");

                    try
                    {
                        SoftInfo.LoadSoftInfo();
                    }
                    catch
                    {
                        Response.Write("<script type=\"text/javascript\">top.location.href='index.aspx';</script>");
                        Response.End();
                    }

                    //升级general.config文件
                    try
                    {
                        GeneralConfigs.Serialiaze(GeneralConfigs.GetConfig(), Server.MapPath("../config/general.config"));
                    }
                    catch { }


                    Response.Write("<script type=\"text/javascript\">top.location.href='index.aspx';</script>");
                    Response.End();
                    return;
                }
                else
                {
                    Response.Redirect("syslogin.aspx?result=2");
                    return;
                }
            }
            else
            {
                Response.Redirect("syslogin.aspx?result=1");
                return;
            }
        }