=cut
sub create {
- my ($self, $nickname, $email, $opts) = @_;
+ my ($self, $nickname, $email, $passwd, $opts) = @_;
return if $self->check_readonly;
$opts ||= {};
# check: nickname is given?
if ($nickname =~ m/\A\s+\z/) {
- return { error => ERROR_NICKNAME_NOT_GIVEN };
+ $self->set_error("nicknake not given", ERROR_NICKNAME_NOT_GIVEN);
+ return;
}
my $matchname = $self->_nickname_to_matchname($nickname);
# check: email is valid?
if (!Email::Valid->address($email)) {
- return { error => ERROR_INVALID_ADDRESS };
+ $self->set_error("invalid address", ERROR_INVALID_ADDRESS);
+ return;
}
# check: nickname already exists?
my $user = $self->select(nickname => $nickname);
if ($user) {
- return { error => ERROR_USER_EXISTS };
+ $self->set_error("user exists", ERROR_USER_EXISTS);
+ return;
}
# check: mail already registered?
$user = $self->select(email => $email);
if ($user) {
- return { error => ERROR_MAIL_REGISTERED };
+ $self->set_error("Mail registered", ERROR_MAIL_REGISTERED);
+ return;
}
# start transaction
my $sth;
# create user and set temporary password
- my $passwd = $self->random_password;
my $enc_passwd = $self->encrypt_password($passwd, '');
$sql = <<"EOSQL";
INSERT INTO users (uid, realemail, nickname, matchname, seclev, passwd)
if (!$uid) {
$dbh->rollback;
$self->disconnect_db;
- return { error => ERROR_INSERT_USER_FAILED };
+ $self->set_error('insert user failed', ERROR_INSERT_USER_FAILED);
+ return;
}
# create users_info, etc.
EOSQL
$result = $dbh->do($sql, undef, $uid, '');
if (!$result) {
+ $self->set_error($dbh->errstr, $dbh->err);
$dbh->rollback;
$self->disconnect_db;
- return { error => ERROR_DO_SQL };
+ return;
}
for my $table (qw{users_prefs users_comments users_hits users_class}) {
$sql = "INSERT INTO $table (uid) VALUES (?)";
$result = $dbh->do($sql, undef, $uid);
if (!$result) {
+ $self->set_error($dbh->errstr, $dbh->err);
$dbh->rollback;
$self->disconnect_db;
- return { error => ERROR_DO_SQL };
+ return;
}
}
EOSQL
$result = $dbh->do($sql, undef, $uid, '', '', '');
if (!$result) {
+ $self->set_error($dbh->errstr, $dbh->err);
$dbh->rollback;
$self->disconnect_db;
- return { error => ERROR_DO_SQL };
+ return;
}
# finish
$dbh->commit;
$self->disconnect_db;
- return { error => 0, uid => $uid, password => $passwd };
+ return $uid;
}
=head2 clearRookie($uid, $time)