Skip to content
Permalink
Browse files

Merge branch 'feature/signup_form' into 'master'

Feature/Signup Form 报名表支持学术测试 #33

See merge request imunc/iplacard!103
  • Loading branch information...
fengkaijia committed Jun 8, 2019
2 parents 67b70e9 + 9e40dc0 commit c54796984634ea18cb33a8ac6bdbbf439a3dfe5b
@@ -223,135 +223,6 @@ function logout()
redirect('account/login');
}
/**
* 报名
*/
function signup()
{
//检查登录情况
if(is_logged_in())
{
redirect('');
return;
}
$this->load->model('delegate_model');
$unique_id = option('signup_unique_identifier', 'email');
if(!in_array($unique_id, array('email', 'phone')))
$unique_id = "profile_$unique_id";
$types = option('signup_type', array('delegate', 'observer', 'volunteer', 'teacher'));
$vars['type'] = array();
foreach($types as $type)
{
$vars['type'][$type] = $this->delegate_model->application_type_text($type);
}
$profiles = option('profile_list_general', array());
$vars['profiles'] = $profiles;
$this->form_validation->set_error_delimiters('<div class="help-block">', '</div>');
$this->form_validation->set_rules('name', '姓名', 'trim|required');
$this->form_validation->set_rules('email', '电子邮箱地址', 'trim|required|valid_email|is_unique[user.email]'.($unique_id == 'email' ? '|callback__check_unique_id' : ''));
$this->form_validation->set_rules('phone', '手机号', 'trim|required|integer|exact_length[11]|is_unique[user.phone]'.($unique_id == 'phone' ? '|callback__check_unique_id' : ''));
$this->form_validation->set_rules('type', '申请类型', 'trim|required|in_list['.join(',', $types).']');
if(!in_array($unique_id, array('email', 'phone')))
$this->form_validation->set_rules($unique_id, '此项注册信息', 'trim|required|callback__check_unique_id');
$this->form_validation->set_message('_check_unique_id', "相同的注册信息已经存在。");
if($this->form_validation->run() == true)
{
//生成随机密码
$this->load->helper('string');
$password = random_string('alnum', 8);
//新建用户
$user_data = array(
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'type' => 'delegate',
'password' => $password,
'pin_password' => option('pin_default_password', 'iPlacard'),
'phone' => $this->input->post('phone'),
'reg_time' => time()
);
$uid = $this->user_model->edit_user($user_data);
//增加代表数据
$this->delegate_model->add_delegate($uid);
$delegate_data = array(
'status' => 'application_imported',
'application_type' => $this->input->post('type'),
'unique_identifier' => $this->input->post($unique_id)
);
$this->delegate_model->edit_delegate($delegate_data, $uid);
//导入资料
foreach($profiles as $name => $item)
{
$this->delegate_model->add_profile($uid, $name, trim($this->input->post("profile_$name")));
}
//发送邮件
$this->load->library('email');
$this->load->library('parser');
$this->load->helper('date');
$data = array(
'uid' => $uid,
'name' => $this->input->post('name'),
'email' => $this->input->post('email'),
'password' => $password,
'time' => unix_to_human(time()),
'url' => base_url(),
);
$this->email->to($this->input->post('email'));
$this->email->subject('iPlacard 帐户登录信息');
$this->email->html($this->parser->parse_string(option('email_delegate_account_created', "您已成功报名。您的 iPlacard 帐户已经于 {time} 创建。帐户信息如下:\n\n"
. "\t登录邮箱:{email}\n"
. "\t密码:{password}\n\n"
. "请使用以上信息访问:\n\n"
. "\t{url}\n\n"
. "登录并开始通过 iPlacard 了解您的申请进度。"), $data, true));
if(!$this->email->send())
{
$this->system_model->log('notice_failed', array('id' => $uid, 'type' => 'email', 'content' => 'delegate_account_created'));
}
//发送短信通知
if(option('sms_enabled', false))
{
$this->load->model('sms_model');
$this->load->library('sms');
$this->sms->to($uid);
$this->sms->message('您已成功报名,一封含有登录信息的邮件已经发送到您的电子邮箱,请通过提供的信息登录 iPlacard 了解申请进度。如果未能收到通知邮件,请与我们联系。');
if(!$this->sms->queue())
{
$this->system_model->log('notice_failed', array('id' => $uid, 'type' => 'sms', 'content' => 'delegate_account_created'));
}
}
$this->delegate_model->add_event($uid, 'application_imported');
$this->user_model->add_message($uid, '您已成功报名。您的参会申请已经开始审核。');
$this->system_model->log('application_imported', array('ip' => $this->input->ip_address(), 'id' => $uid, 'ui' => true), 0);
$this->ui->alert('您已成功报名,请使用发送到您刚才登记邮箱中的密码登录 iPlacard。', 'success', true);
redirect('account/login');
return;
}
$this->ui->title('报名');
$this->ui->background();
$this->load->view('delegate/signup', $vars);
}
/**
* 两步验证
*/
@@ -2455,17 +2326,6 @@ function _check_confirm($checkbox)
return false;
}
/**
* 检查唯一身份标识符是否已经存在
*/
function _check_unique_id($str)
{
if(empty($str))
return true;
return !$this->delegate_model->get_delegate_id('unique_identifier', $str);
}
/**
* 转换手机为对应的邮箱
*/

0 comments on commit c547969

Please sign in to comment.
You can’t perform that action at this time.