一、登录模块:
<form action="<?php echo JRoute::_('index.php?option=com_users&task=user.login'); ?>" method="post" class="form-validate form-horizontal well">
<div>用户名:<input name="username" type="text" /></div>
<div>密码:<input name="password" type="password" /></div>
<div>密码:<input type="submit" value="提交"/></div>
<?php echo JHtml::_('form.token'); ?>
</form>
二、注销模块:
<form action="<?= JRoute::_('index.php?option=com_users'); ?>" method="post" id="login-form" class="form-vertical">
<div class="login-greeting"> 登录用户的角色
</div>
<div class="logout-button">
<input type="submit" name="Submit" class="btn btn-primary" value="退出">
<input type="hidden" name="option" value="com_users">
<input type="hidden" name="task" value="user.logout">
<input type="hidden" name="return" value="<?= base64_encode(注销后返回的链接地址[注:此处需要base64转码]); ?>">
<?php echo JHtml::_('form.token'); ?>
</form>
三、注册模块:
<form id="member-profile" action="<?php echo JRoute::_('index.php?option=com_users&task=profile.save'); ?>" method="post" class="form-validate form-horizontal well" enctype="multipart/form-data">
<fieldset>
<legend>编辑您的用户资料</legend>
<input type="hidden" name="jform[id]" id="jform_id" value="">
<div class="control-group">
<div class="control-label">
<label id="jform_name-lbl" for="jform_name" class="hasTooltip required">姓名:</label> </div>
<div class="controls">
<input type="text" name="jform[name]" id="jform_name">
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="jform_username-lbl" for="jform_username" class="hasTooltip">用户名:</label>
</div>
<div class="controls">
<input type="text" name="jform[username]" id="jform_username">
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="jform_password1-lbl" for="jform_password1" class="hasTooltip">密码:</label>
</div>
<div class="controls">
<input type="password" name="jform[password1]" id="jform_password1">
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="jform_password2-lbl" for="jform_password2" class="hasTooltip">验证密码:</label>
</div>
<div class="controls">
<input type="password" name="jform[password2]" id="jform_password2">
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="jform_email1-lbl" for="jform_email1" class="hasTooltip required">E邮箱地址:</label>
</div>
<div class="controls">
<input type="email" name="jform[email1]" class="validate-email required" id="jform_email1">
</div>
</div>
<div class="control-group">
<div class="control-label">
<label id="jform_email2-lbl" for="jform_email2" class="hasTooltip required">重填邮箱地址:</label>
</div>
<div class="controls">
<input type="email" name="jform[email2]" class="validate-email required" id="jform_email2">
</div>
</div>
</fieldset>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary validate"><span>提交</span></button>
<input type="hidden" name="option" value="com_users" />
<input type="hidden" name="task" value="profile.save" />
</div>
</div>
<?php echo JHtml::_('form.token'); ?>
</form>
注:
1、components\com_users\controllers\profile.php中的‘save函数’需要修改:
//在删除username时,需要增加判断此操作是否为添加// Unset the username if it should not be overwritten$username = $data['username'];$isUsernameCompliant = $this->getState('user.username.compliant');
if ($userId && !JComponentHelper::getParams('com_users')->get('change_login_name') && $isUsernameCompliant){
unset($data['username']);
}
2、前台注册的用户需要后台为其添加默认用户组: 编写‘addUserOfGroup($user_id)’函数(该函数在前端注册新用户时执行)
public function addUserOfGroup($user_id,$group_id = null){$db = JFactory::getDbo();$query = $db->getQuery(true);$query->insert('#__user_usergroup_map')->columns(array('user_id','group_id'));$values = array();$values[] = $user_id;$values[] = empty($group_id) ? 2 : $group_id;$query->values(implode(',',$values));try {$db->setQuery($query);$db->execute();return true;} catch(EXception $e){return false;}}
四、更新模块:
更新与注册类似。