uchome二次开发,填写一些额外的字段
2010-10-25 杜世伟
需求:uchome二次开发,在注册的时候,需要填写一些额外的字段,比如,年龄,体重,真实姓名和手机号等。基本思路就是这样,这里添加的字段是”area”,如果想添加在uc_members表中,只需在这个表中添加字段要添加的字段既可
1.uc_client/control/user.php
改动代码
01 |
function onregister() { |
02 |
$this->init_input(); |
03 |
$username = $this->input('username'); |
04 |
$password = $this->input('password'); |
05 |
$email = $this->input('email'); |
06 |
$questionid = $this->input('questionid'); |
07 |
$answer = $this->input('answer'); |
08 |
$area = $this->input('area');//自定义字段 |
09 |
|
10 |
if(($status = $this->_check_username($username)) < 0) { |
11 |
return $status; |
12 |
} |
13 |
if(($status = $this->_check_email($email)) < 0) { |
14 |
return $status; |
15 |
} |
16 |
$uid = $_ENV['user']->add_user($username, $password, $email, 0, $questionid, $answer, $area); |
17 |
return $uid; |
18 |
} |
19 |
|
20 |
2.uc_client/model/user.php |
21 |
改动代码: |
22 |
function add_user($username, $password, $email, $uid = 0, $questionid = '', $answer = '', $area) { |
23 |
$salt = substr(uniqid(rand()), -6); |
24 |
$password = md5(md5($password).$salt); |
25 |
$sqladd = $uid ? "uid='".intval($uid)."'," : ''; |
26 |
$sqladd .= $questionid > 0 ? " secques='".$this->quescrypt($questionid, $answer)."'," : " secques='',"; |
27 |
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."members SET $sqladd username='$username', password='$password', email='$email', area='$area', regip='".$this- |
28 |
|
29 |
>base->onlineip."', regdate='".$this->base->time."', salt='$salt'"); |
30 |
$uid = $this->db->insert_id(); |
31 |
$this->db->query("INSERT INTO ".UC_DBTABLEPRE."memberfields SET uid='$uid'"); |
32 |
return $uid; |
33 |
} |
3.uc_client/client.php
改动代码
01 |
/** |
02 |
* 用户注册 |
03 |
* |
04 |
* @param string $username 用户名 |
05 |
* @param string $password 密码 |
06 |
* @param string $email Email |
07 |
* @param int $questionid 安全提问 |
08 |
* @param string $answer 安全提问答案 |
09 |
* @return int |
10 |
-1 : 用户名不合法 |
11 |
-2 : 包含不允许注册的词语 |
12 |
-3 : 用户名已经存在 |
13 |
-4 : email 格式有误 |
14 |
-5 : email 不允许注册 |
15 |
-6 : 该 email 已经被注册 |
16 |
>1 : 表示成功,数值为 UID |
17 |
*/ |
18 |
function uc_user_register($username, $password, $email, $questionid = '', $answer = '', $area) { |
19 |
return call_user_func(UC_API_FUNC, 'user', 'register', array('username'=>$username, 'password'=>$password, 'email'=>$email, 'questionid'=>$questionid, 'answer'=>$answer, |
20 |
|
21 |
'area'=>$area)); |
22 |
} |
4.source/do_register.php
改动代码:添加$area变量
01 |
[/php] |
02 |
$area = $_POST['area']; |
03 |
$newuid = uc_user_register($username, $password, $email,$area); |
04 |
if($newuid <= 0) { |
05 |
if($newuid == -1) { |
06 |
showmessage('user_name_is_not_legitimate'); |
07 |
} elseif($newuid == -2) { |
08 |
showmessage('include_not_registered_words'); |
09 |
} elseif($newuid == -3) { |
10 |
showmessage('user_name_already_exists'); |
11 |
} elseif($newuid == -4) { |
12 |
showmessage('email_format_is_wrong'); |
13 |
} elseif($newuid == -5) { |
14 |
showmessage('email_not_registered'); |
15 |
} elseif($newuid == -6) { |
16 |
showmessage('email_has_been_registered'); |
17 |
} else { |
18 |
showmessage('register_error'); |
19 |
} |
20 |
} else { |
21 |
$setarr = array( |
22 |
'uid' => $newuid, |
23 |
'username' => $username, |
24 |
'area' => $area,//这里似乎不用修改,没仔细看 |
25 |
'groupid' => 2, |
26 |
'password' => md5("$newuid|$_SGLOBAL[timestamp]"), //本地密码随机生成 |
27 |
'dateline' => $_SGLOBAL['timestamp'], |
28 |
'updatetime' => $_SGLOBAL['timestamp'], |
29 |
'lastlogin' => $_SGLOBAL['timestamp'], |
30 |
'ip' => $_SGLOBAL['onlineip'] |
31 |
); |
32 |
//更新本地用户库 |
33 |
inserttable('members', $setarr, 0, true); |
34 |
|
35 |
//设置cookie |
36 |
ssetcookie('auth', authcode("$setarr[password]\t$setarr[uid]", 'ENCODE'), 2592000); |
37 |
ssetcookie('loginuser', $username, 31536000); |
38 |
|
39 |
showmessage('registered', rawurldecode($refer)); |
40 |
} |
41 |
[php] |
5.同时修改模板文件do_regiester.htm加入相应的字段
肯能有些数据存uchome_space表更好些,思路就是在source/do_register.php去更新表uchome_space和uchome_spacefield,例如修改修改如下,更新真实姓名,和手机号字段
在source/do_register.php下找到
$friendstr = empty($fuids)?'':implode(',', $fuids);
updatetable('space', array('friendnum'=>count($fuids), 'pokenum'=>count($pokes)), array('uid'=>$newuid));
updatetable('spacefield', array('friend'=>$friendstr, 'feedfriend'=>$friendstr), array('uid'=>$newuid));
/*- 2010-10-22 16:41 修改如下,更新真实姓名,和手机号字段-*/
updatetable('space', array('friendnum'=>count($fuids), 'pokenum'=>count($pokes),'name'=>$name,'namestatus'=>1), array('uid'=>$newuid));
updatetable('spacefield', array('friend'=>$friendstr, 'feedfriend'=>$friendstr,'mobile'=>$mobile), array('uid'=>$newuid));
标签: uchome二次开发,uchome填写一些额外的字段,uchome添加的字段
热门日志
分类
- git(9)
- Mac(7)
- C(1)
- memcache(1)
- Python(32)
- Vim(8)
- sed(2)
- ansible(3)
- awk(4)
- shell(3)
- Django(4)
- ssdb(1)
- bat(4)
- svn(0)
- docker(1)
- Tornado(1)
- go(2)
- 架构(19)
- Vue(1)
- game(2)
- AI(1)
- Windows(8)
- Java(8)
- Mysql(38)
- Ajax(2)
- Jsp(1)
- Struts(8)
- Linux(73)
- JavaScript(39)
- Staruml(0)
- Mouth(1)
- Html(6)
- Php(102)
- Message(52)
- Lua(10)
- Compute(1)
- Redis(7)
- Nginx(12)
- Jquery(1)
- Apache(1)
- cocos2d-x(8)
- about(1)

