[英]Account activation, CodeIgniter
I want to create an account activation where after registering, a link would be sent to an administrator (or one) email whereby the admin just has to click that link to activate that account. 我想创建一个帐户激活,在注册后,链接将发送给管理员(或一个)电子邮件,管理员只需单击该链接即可激活该帐户。
I have the registration and login working. 我有注册和登录的工作。 I'm using MySQL Workbench and have a "flag" or rather just a field in my accounts table (named user_login
) to tell whether the account is enabled or disabled, which is disabled by default after registration. 我正在使用MySQL Workbench,并且在我的帐户表中有一个“标志”或一个字段(名为user_login
)来告诉您该帐户是启用还是禁用,注册后默认情况下是禁用的。
I am stuck and sending a link through email, I'm not sure where to begin. 我被困住了,并通过电子邮件发送链接,我不确定从哪里开始。 That link that I want to send would contain a random string and would be sent to the admin, say abc/123/random?stringis=1234
. 我要发送的链接将包含一个随机字符串,并将被发送给管理员,例如abc/123/random?stringis=1234
。 Then the admin would just have to open his email and click on the string and then that specific user's account would be activated. 然后,管理员只需打开他的电子邮件并单击字符串,然后即可激活该特定用户的帐户。 I found this and this but that's just for how to send a link through email. 我发现了这 一点,但这只是如何通过电子邮件发送链接。
I don't have an idea on the logic. 我对逻辑一无所知。 Do I create a function whereby the link would go directly to the function and from there, it would change the value in my table to enabled
or whatever I call it so that the user's account is counted as activated? 我是否创建了一个函数,该链接将直接转到该函数,然后从那里将其链接表中的值更改为enabled
或我称之为的名称,以便将该用户的帐户计为已激活? Do I need to create a new field to match the random generated string then? 我是否需要创建一个新字段来匹配随机生成的字符串?
Main idea is I'm trying to do like those typical sites whereby a link would be sent to the user to activate the account once he/she clicks it in the email, but this time just to a specific email which is the admin's. 主要想法是,我想像那些典型的网站那样做,通过该链接,一旦用户在电子邮件中单击该帐户,该链接就会发送给用户以激活该帐户,但这一次仅是管理员的特定电子邮件。
EDIT: 编辑:
In controller 在控制器中
public function activate_user($activation_code)
{
$result = $this->home_model->activate($activation_code);
if($result != FALSE)
{
echo "You have activated :".$result[0]->user_id.".";
}
else
{
echo "Activation failed, something went wrong.";
}
}
In Model: 在模型中:
public function activate($activation_link)
{
$this->db->select('*');
$this->db->from('user_login');
$this->db->where('activation_link', $activation_link);
$query = $this->db->get();
if($query->num_rows() == 1)
{
return $query->result();
}
else
{
return FALSE;
}
}
为此,当用户在站点中注册时,您需要在表中添加一个称为activation_link
字段,然后生成随机字符串,并将其存储在activation_link
然后将链接发送给用户,以便一旦用户返回,然后检查链接并激活该用户。
First 第一
Database add two column 数据库添加两列
After registration Success 注册成功后
Link 链接
link should be I strongly prefer userid in activation url because it's remove the link duplication. 链接应该是我强烈希望激活网址中的userid,因为它删除了链接重复。 http://sitename.com/activation/ {user_id}/{hash} http://sitename.com/activation/ {user_id} / {hash}
in controller 在控制器中
public function activation($user_id,$hash)
{
$timeOfexpiration = 3600;
$data = $this->model->get_data($id,$hash);
if(!$data)
{
return false
}
//if user found
//check expiration of linke
//like
if($data['activation_time']+$timeOfexpiration < now())
{
return true;
}
else
{
return false;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.