correctly use Confirm_address
darcs-hash:20080622161607-34904-d8e042b80fe6acd3cb6ad763216a0b1817752cac.gz
This commit is contained in:
parent
403039510c
commit
4fd1f6246d
@ -33,27 +33,37 @@ class ConfirmemailAction extends Action {
|
|||||||
$this->client_error(_t('No confirmation code.'));
|
$this->client_error(_t('No confirmation code.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$confirm_email = Confirm_email::staticGet('code', $code);
|
$confirm = Confirm_address::staticGet('code', $code);
|
||||||
if (!$confirm_email) {
|
if (!$confirm) {
|
||||||
$this->client_error(_t('Confirmation code not found.'));
|
$this->client_error(_t('Confirmation code not found.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$cur = common_current_user();
|
$cur = common_current_user();
|
||||||
if ($cur->id != $confirm_email->user_id) {
|
if ($cur->id != $confirm->user_id) {
|
||||||
$this->client_error(_t('That confirmation code is not for you!'));
|
$this->client_error(_t('That confirmation code is not for you!'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($cur->email == $confirm_email->email) {
|
$type = $confirm->address_type;
|
||||||
$this->client_error(_t('That email address is already confirmed.'));
|
if (!in_array($type, array('email', 'jabber', 'sms'))) {
|
||||||
return;
|
$this->server_error(_t('Unrecognized address type ') . $type);
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
if ($cur->$type == $confirm->address) {
|
||||||
|
$this->client_error(_t('That address has already been confirmed.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$cur->query('BEGIN');
|
$cur->query('BEGIN');
|
||||||
|
|
||||||
$orig_user = clone($cur);
|
$orig_user = clone($cur);
|
||||||
|
|
||||||
|
$cur->$type = $confirm->address;
|
||||||
|
|
||||||
|
if ($type == 'sms') {
|
||||||
|
$cur->carrier = ($confirm->address_extra)+0;
|
||||||
|
}
|
||||||
|
|
||||||
$cur->email = $confirm_email->email;
|
$result = $cur->updateKeys($orig_user);
|
||||||
$result = $cur->updateKeys($orig_user);
|
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
common_log_db_error($cur, 'UPDATE', __FILE__);
|
common_log_db_error($cur, 'UPDATE', __FILE__);
|
||||||
@ -61,20 +71,20 @@ class ConfirmemailAction extends Action {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $confirm_email->delete();
|
$result = $confirm->delete();
|
||||||
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
common_log_db_error($confirm_email, 'DELETE', __FILE__);
|
common_log_db_error($confirm, 'DELETE', __FILE__);
|
||||||
$this->server_error(_t('Couldn\'t delete email confirmation.'));
|
$this->server_error(_t('Couldn\'t delete email confirmation.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cur->query('COMMIT');
|
$cur->query('COMMIT');
|
||||||
|
|
||||||
common_show_header(_t('Confirm E-mail Address'));
|
common_show_header(_t('Confirm Address'));
|
||||||
common_element('p', NULL,
|
common_element('p', NULL,
|
||||||
_t('The email address "') . $cur->email .
|
_t('The address "') . $cur->email .
|
||||||
_t('" has been confirmed for your account.'));
|
_t('" has been confirmed for your account.'));
|
||||||
common_show_footer(_t('Confirm E-mail Address'));
|
common_show_footer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,10 +138,10 @@ class ProfilesettingsAction extends SettingsAction {
|
|||||||
|
|
||||||
# We don't update email directly; it gets done by confirmemail
|
# We don't update email directly; it gets done by confirmemail
|
||||||
|
|
||||||
$confirm = new Confirm_email();
|
|
||||||
$confirm->code = common_good_rand(16);
|
$confirm->code = common_good_rand(16);
|
||||||
$confirm->user_id = $user->id;
|
$confirm->user_id = $user->id;
|
||||||
$confirm->email = $email;
|
$confirm->address = $email;
|
||||||
|
$confirm->address_type = 'email';
|
||||||
|
|
||||||
$result = $confirm->insert();
|
$result = $confirm->insert();
|
||||||
|
|
||||||
@ -150,6 +150,7 @@ class ProfilesettingsAction extends SettingsAction {
|
|||||||
common_server_error(_t('Couldnt confirm email.'));
|
common_server_error(_t('Couldnt confirm email.'));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
# XXX: try not to do this in the middle of a transaction
|
# XXX: try not to do this in the middle of a transaction
|
||||||
|
|
||||||
mail_confirm_address($confirm->code,
|
mail_confirm_address($confirm->code,
|
||||||
|
@ -120,10 +120,11 @@ class RegisterAction extends Action {
|
|||||||
|
|
||||||
if ($email) {
|
if ($email) {
|
||||||
|
|
||||||
$confirm = new Confirm_email();
|
$confirm = new Confirm_address();
|
||||||
$confirm->code = common_good_rand(16);
|
$confirm->code = common_good_rand(16);
|
||||||
$confirm->user_id = $user->id;
|
$confirm->user_id = $user->id;
|
||||||
$confirm->email = $email;
|
$confirm->address = $email;
|
||||||
|
$confirm->address_type = 'email';
|
||||||
|
|
||||||
$result = $confirm->insert();
|
$result = $confirm->insert();
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
|
@ -13,7 +13,8 @@ class Confirm_address extends DB_DataObject
|
|||||||
public $code; // varchar(32) primary_key not_null
|
public $code; // varchar(32) primary_key not_null
|
||||||
public $user_id; // int(4) not_null
|
public $user_id; // int(4) not_null
|
||||||
public $address; // varchar(255) not_null
|
public $address; // varchar(255) not_null
|
||||||
public $address_type; // varchar(32) not_null
|
public $address_extra; // varchar(255) not_null
|
||||||
|
public $address_type; // varchar(8) not_null
|
||||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||||
|
|
||||||
/* Static get */
|
/* Static get */
|
||||||
|
24
classes/Sms_carrier.php
Normal file
24
classes/Sms_carrier.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Table Definition for sms_carrier
|
||||||
|
*/
|
||||||
|
require_once 'DB/DataObject.php';
|
||||||
|
|
||||||
|
class Sms_carrier extends DB_DataObject
|
||||||
|
{
|
||||||
|
###START_AUTOCODE
|
||||||
|
/* the code below is auto generated do not remove the above tag */
|
||||||
|
|
||||||
|
public $__table = 'sms_carrier'; // table name
|
||||||
|
public $id; // int(4) primary_key not_null
|
||||||
|
public $name; // varchar(64) unique_key
|
||||||
|
public $email_pattern; // varchar(255) not_null
|
||||||
|
public $created; // datetime() not_null
|
||||||
|
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||||
|
|
||||||
|
/* Static get */
|
||||||
|
function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Sms_carrier',$k,$v); }
|
||||||
|
|
||||||
|
/* the code above is auto generated do not remove the tag below */
|
||||||
|
###END_AUTOCODE
|
||||||
|
}
|
@ -36,6 +36,7 @@ class User extends DB_DataObject
|
|||||||
public $email; // varchar(255) unique_key
|
public $email; // varchar(255) unique_key
|
||||||
public $jabber; // varchar(255) unique_key
|
public $jabber; // varchar(255) unique_key
|
||||||
public $sms; // varchar(64) unique_key
|
public $sms; // varchar(64) unique_key
|
||||||
|
public $carrier; // int(4)
|
||||||
public $uri; // varchar(255) unique_key
|
public $uri; // varchar(255) unique_key
|
||||||
public $created; // datetime() not_null
|
public $created; // datetime() not_null
|
||||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||||
@ -68,7 +69,7 @@ class User extends DB_DataObject
|
|||||||
|
|
||||||
function updateKeys(&$orig) {
|
function updateKeys(&$orig) {
|
||||||
$parts = array();
|
$parts = array();
|
||||||
foreach (array('nickname', 'email') as $k) {
|
foreach (array('nickname', 'email', 'jabber', 'sms', 'carrier') as $k) {
|
||||||
if (strcmp($this->$k, $orig->$k) != 0) {
|
if (strcmp($this->$k, $orig->$k) != 0) {
|
||||||
$parts[] = $k . ' = ' . $this->_quote($this->$k);
|
$parts[] = $k . ' = ' . $this->_quote($this->$k);
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ url = U
|
|||||||
code = 130
|
code = 130
|
||||||
user_id = 129
|
user_id = 129
|
||||||
address = 130
|
address = 130
|
||||||
|
address_extra = 130
|
||||||
address_type = 130
|
address_type = 130
|
||||||
modified = 384
|
modified = 384
|
||||||
|
|
||||||
@ -86,6 +87,17 @@ modified = 384
|
|||||||
id = K
|
id = K
|
||||||
uri = U
|
uri = U
|
||||||
|
|
||||||
|
[sms_carrier]
|
||||||
|
id = 129
|
||||||
|
name = 2
|
||||||
|
email_pattern = 130
|
||||||
|
created = 142
|
||||||
|
modified = 384
|
||||||
|
|
||||||
|
[sms_carrier__keys]
|
||||||
|
id = K
|
||||||
|
name = U
|
||||||
|
|
||||||
[subscription]
|
[subscription]
|
||||||
subscriber = 129
|
subscriber = 129
|
||||||
subscribed = 129
|
subscribed = 129
|
||||||
@ -118,6 +130,7 @@ password = 2
|
|||||||
email = 2
|
email = 2
|
||||||
jabber = 2
|
jabber = 2
|
||||||
sms = 2
|
sms = 2
|
||||||
|
carrier = 1
|
||||||
uri = 2
|
uri = 2
|
||||||
created = 142
|
created = 142
|
||||||
modified = 384
|
modified = 384
|
||||||
|
@ -29,6 +29,14 @@ create table avatar (
|
|||||||
index avatar_profile_id_idx (profile_id)
|
index avatar_profile_id_idx (profile_id)
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
create table sms_carrier (
|
||||||
|
id integer primary key comment 'primary key for SMS carrier',
|
||||||
|
name varchar(64) unique key comment 'name of the carrier',
|
||||||
|
email_pattern varchar(255) not null comment 'sprintf pattern for making an email address from a phone number',
|
||||||
|
created datetime not null comment 'date this record was created',
|
||||||
|
modified timestamp comment 'date this record was modified'
|
||||||
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
/* local users */
|
/* local users */
|
||||||
|
|
||||||
create table user (
|
create table user (
|
||||||
@ -38,6 +46,7 @@ create table user (
|
|||||||
email varchar(255) unique key comment 'email address for password recovery etc.',
|
email varchar(255) unique key comment 'email address for password recovery etc.',
|
||||||
jabber varchar(255) unique key comment 'jabber ID for notices',
|
jabber varchar(255) unique key comment 'jabber ID for notices',
|
||||||
sms varchar(64) unique key comment 'sms phone number',
|
sms varchar(64) unique key comment 'sms phone number',
|
||||||
|
carrier integer comment 'foreign key to sms_carrier' references sms_carrier (id),
|
||||||
uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
|
uri varchar(255) unique key comment 'universally unique identifier, usually a tag URI',
|
||||||
created datetime not null comment 'date this record was created',
|
created datetime not null comment 'date this record was created',
|
||||||
modified timestamp comment 'date this record was modified'
|
modified timestamp comment 'date this record was modified'
|
||||||
@ -151,6 +160,7 @@ create table confirm_address (
|
|||||||
code varchar(32) not null primary key comment 'good random code',
|
code varchar(32) not null primary key comment 'good random code',
|
||||||
user_id integer not null comment 'user who requested confirmation' references user (id),
|
user_id integer not null comment 'user who requested confirmation' references user (id),
|
||||||
address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
|
address varchar(255) not null comment 'address (email, Jabber, SMS, etc.)',
|
||||||
address_type varchar(32) not null comment 'address type ("email", "jabber", "sms")',
|
address_extra varchar(255) not null comment 'carrier ID, for SMS',
|
||||||
|
address_type varchar(8) not null comment 'address type ("email", "jabber", "sms")',
|
||||||
modified timestamp comment 'date this record was modified'
|
modified timestamp comment 'date this record was modified'
|
||||||
);
|
) ENGINE=InnoDB;
|
||||||
|
Loading…
Reference in New Issue
Block a user