• dedecms--在后台增加会员添加


    最近在研究dedecms需要前台页面不允许会员注册,而会员帐号是管理员在后台添加的,首先我们得在后台的栏目选项中有会员添加这一栏目;

    1:在dede/inc的文件夹下面找到inc_memu.php;找到会员那个栏目,加一行:<m:item name='会员添加管理' link='member_add.php' rank='member_List' target='main' />

    2:创建会员添加的htm页面:我自己命名为:member_add.htm,这个页面是后台页面,所以在dede/templets里面;

    member_add.htm页面代码:

    <html>
    <head>
    <meta charset="utf-8">
    <title>添加会员</title> <link href='img/base.css' rel='stylesheet' type='text/css'>
    <script language='javascript' src='../data/enums/area.js'></script>
    <script> function checkSubmit() {
    if(document.form2.email.value=="") {
    document.form2.email.focus();
    alert("Email不能为空");
    return false;
    }
    if(document.form2.uname.value=="") {
    document.form2.uname.focus();
    alert("用户昵称不能为空");
    return false; }
    }
    </script>
    </head>
    <body leftmargin='8' topmargin='8'>
    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#D1DDAA">
    <tr>
    <td height="19" background="img/tbg.gif"><a href='<?php echo $ENV_GOBACK_URL; ?>'>
    <b>会员管理 </b></a> 添加会员
    </td>
    </tr>
    <tr>
    <td height="200" bgcolor="#FFFFFF" align='center'>
    <table width="98%" border="0" cellspacing="0" cellpadding="6" >
    <tr> <td colspan="2" height="10" >
    </td>
    </tr>
    <form name="form2" action="member_add.php" method="post" onSubmit="return checkSubmit();">
    <input type="hidden" name="dopost" value="add" />
    <tr>
    <td width="17%" align="right" class='bline'>用户名</td>
    <td width="83%" class='bline'>
    <input name="userid" type="text" value="" id="userid" size="20" style="150px;height:20px" /> </td>
    </tr>
    <tr>
    <td align="right" class='bline'>用户密码</td>
    <td class='bline'> <input type="password" name="pwd" id="pwd" style="150px;height:20px"/> </td>
    </tr>
    <tr>
    <td align="right" class='bline'>用户类型</td>
    <td class='bline'> <?php echo $row['mtype']; ?>
    <input type="radio" name="mtype" class="np" value="个人" checked='1'/> 个人 <input type="radio" name="mtype" class="np" value="企业" />企业 </td>
    </tr>
    <tr>
    <td align="right" class='bline'>电子邮箱</td>
    <td class='bline'> <input name="email" type="text" id="email" value="<?php echo $row['email']?>" style="150px;height:20px" /> </td>
    </tr>
    <tr>
    <td align="right" class='bline'>用户昵称</td>
    <td class='bline'> <input name="uname" type="text" value="<?php echo $row['uname']?>" id="uname" size="20" style="150px;height:20px" /> </td>
    </tr>
    <tr> <td align="right" class='bline'>性别</td> <td class='bline'>
    <input type="radio" name="sex" class="np" value="男" checked='1'/> 男
    <input type="radio" name="sex" class="np" value="女" /> 女
    <input type="radio" name="sex" class="np" value="" /> 保密 </td>
    </tr>
    <tr>
    <td align="right" class='bline'>等级</td>
    <td class='bline'>
    <?php
    $MemberTypes = '';
    $dsql->SetQuery("Select rank,membername From `dede_arcrank` where rank>0");
    $dsql->Execute('n');
    $MemberTypes[0] = "限制会员";
    while($nrow = $dsql->GetObject('n')){ $MemberTypes[$nrow->rank] = $nrow->membername; }
    $options = "<select name='rank' style='80px'> ";
    foreach($MemberTypes as $k=>$v) {
    $v=iconv('gb2312', 'utf-8', $v);
    if($k!=$row['rank']) $options .= "<option value='$k'>$v</option> "; else $options .= "<option value='0' selected>限制会员</option> "; } $options .= "</select> "; echo $options; ?></td>
    </tr>
    <tr> <td align="right" class='bline'>有效时间</td> <td class='bline'>
    <input type="radio" name="exptime" class="np" value="30" /> 一个月
    <input type="radio" name="exptime" class="np" value="7" checked='1'/> 一周
    <input type="radio" name="exptime" class="np" value="1" /> 一天 </td>
    </tr>
    <tr>
    <td height="67" align="right" ></td> <td height="67" >
    <input type="submit" name="Submit" value="确定添加" class='coolbg' />
    <input type="reset" name="Submit22" value="重置表单" class='coolbg' /> </td>
    </tr>
    </form>
    </table>
    </td>
    </tr>
    </table>
    </body>
    </html>

    3:htm页面有了,那么我们需要在dede文件夹下面创建member_add.php页面来写php代码了

    member_add.php代码:

    <?php
    require(dirname(__FILE__)."/config.php");
    $ENV_GOBACK_URL = isset($_COOKIE['ENV_GOBACK_URL']) ? "member_main.php" : '';
    if($dopost=="add"){
    $jointime = $logintime = time();
    $loginip = $joinip = GetIP();
    $userid=$userid;
    $pwd=$pwd;

    //因为dedecms默认是的GB2312,所以这里需要将用户类型和用户性别转话为GB2312格式,否则数据库是存储不了的
    $mtype=iconv('utf-8', 'gb2312', $mtype);
    $sex=iconv('utf-8', 'gb2312', $sex);

    //如果管理员没有给会员userid和密码,那么这里系统会随机给会员一个帐号和密码
    if($userid==""){
    $string="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for($i=0;$i<5;$i++){
    $userid.= $string[rand(0,strlen($string)-1)];
    }
    }

    if($pwd==""){
    $password="abcdefghijklmnopqrstuvwxyz1234567890";
    for($i=0;$i<6;$i++){
    $pwd.= $password[rand(0,strlen($password)-1)];
    }

    }

    $uname = HtmlReplace($uname, 1);
    if($cfg_mb_wnameone=='N'){
    $row = $dsql->GetOne("SELECT * FROM `#@__member` WHERE uname LIKE '$uname' ");
    if(is_array($row))
    {
    ShowMsg('用户笔名或公司名称不能重复!', '-1');
    exit();
    }
    }

    if(!CheckEmail($email))
    {
    ShowMsg('Email格式不正确!', '-1');
    exit();
    }
    #api{{
    if(defined('UC_API') && @include_once DEDEROOT.'/uc_client/client.php')
    {
    $uid = uc_user_register($userid, $pwd, $email);
    if($uid <= 0)
    {
    if($uid == -1)
    {
    ShowMsg("用户名不合法!","-1");
    exit();
    }
    elseif($uid == -2)
    {
    ShowMsg("包含要允许注册的词语!","-1");
    exit();
    }
    elseif($uid == -3)
    {
    ShowMsg("你指定的用户名 {$userid} 已存在,请使用别的用户名!","-1");
    exit();
    }
    elseif($uid == -5)
    {
    ShowMsg("你使用的Email 不允许注册!","-1");
    exit();
    }
    elseif($uid == -6)
    {
    ShowMsg("你使用的Email已经被另一帐号注册,请使其它帐号","-1");
    exit();
    }
    else
    {
    ShowMsg("注删失改!","-1");
    exit();
    }
    }
    else
    {
    $ucsynlogin = uc_user_synlogin($uid);
    }
    }
    #/aip}}

    if($cfg_md_mailtest=='Y')
    {
    $row = $dsql->GetOne("SELECT mid FROM `#@__member` WHERE email LIKE '$email' ");
    if(is_array($row))
    {
    ShowMsg('你使用的Email已经被另一帐号注册,请使其它帐号!', '-1');
    exit();
    }
    }

    //检测用户名是否存在
    $row = $dsql->GetOne("SELECT mid FROM `#@__member` WHERE userid LIKE '$userid' ");
    if(is_array($row))
    {
    ShowMsg("你指定的用户名 {$userid} 已存在,请使用别的用户名!", "-1");
    exit();
    }

    //会员的默认金币
    $dfscores = 0;
    $dfmoney = 0;
    $dfrank = $dsql->GetOne("SELECT money,scores FROM `#@__arcrank` WHERE rank='10' ");
    if(is_array($dfrank))
    {
    $dfmoney = $dfrank['money'];
    $dfscores = $dfrank['scores'];
    }

    $mpwd = md5($pwd);

    //这里的echo是因为如果管理员没有给会员帐号和密码的话,系统随机给的密码是md5加密存入数据库的,那么存入后管理员将无法得知会员的帐号密码信息,所以这里输出简单的会员信息为了让管理员管理的
    echo "<table><tr><td>用户名:".$userid."</td></tr><tr><td>用户帐号:".$pwd."</td></tr><tr><td>用户昵称:".$uname."</td></tr></table>";
    $dsql->ExecuteNoneQuery("INSERT INTO dede_member SET `mtype`='$mtype',`userid`='$userid',`pwd`='$mpwd',`uname`='$uname',`sex`='$sex' ,`rank`='$rank',`exptime`='$exptime',`money`='$dfmoney', `email`='$email', `scores`='$dfscores', `matt`='0', `face`='',`safequestion`='0',`safeanswer`='$safeanswer', `jointime`='$jointime',`joinip`='$joinip',`logintime`='$logintime',`loginip`='$loginip';");
    ShowMsg('成功添加一个用户');
    exit();

    }else{
    include DedeInclude('templets/member_add.htm');
    }

    ?>

    这样一个后台会员添加就做好了

  • 相关阅读:
    IDS与IPS功能分析
    CentOS 命令大全
    仿京东放大镜
    CSS垂直水平居中方法总结
    Java学习之计算机基础(一)
    Java 代码学习之理解数据类型中的坑
    Java 代码学习之数组的初始化
    Java中的比较总结
    Java Random介绍
    手机网站开发必修课[2]:浏览器兼容性测试
  • 原文地址:https://www.cnblogs.com/gaoxuqing/p/6913177.html
Copyright © 2020-2023  润新知