Skip to content
Permalink
Browse files

refs #7 summaryデータのinit data用意 && fixed bug

  • Loading branch information
kfly8 committed Sep 27, 2014
1 parent d78c73a commit 2daf40a936fc541841cc50fcb2c408fee7530444
Showing with 91 additions and 9 deletions.
  1. +2 −0 init.sh
  2. +85 −7 perl/lib/Isu4Qualifier/Web.pm
  3. +1 −0 sql/ip_login_last_failure_count.sql
  4. +2 −2 sql/schema.sql
  5. +1 −0 sql/user_login_last_failure_count.sql
@@ -13,3 +13,5 @@ mysql -h ${myhost} -P ${myport} -u ${myuser} -e "DROP DATABASE IF EXISTS ${mydb}
mysql -h ${myhost} -P ${myport} -u ${myuser} ${mydb} < sql/schema.sql
mysql -h ${myhost} -P ${myport} -u ${myuser} ${mydb} < sql/dummy_users.sql
mysql -h ${myhost} -P ${myport} -u ${myuser} ${mydb} < sql/dummy_log.sql
mysql -h ${myhost} -P ${myport} -u ${myuser} ${mydb} < sql/ip_login_last_failure_count.sql
mysql -h ${myhost} -P ${myport} -u ${myuser} ${mydb} < sql/user_login_last_failure_count.sql
@@ -65,7 +65,7 @@ sub calculate_password_hash {
sub user_locked {
my ($self, $user) = @_;
my $summary = $self->db->select_row(
'SELECT last_failure_count FROM user_login_failure_count WHERE user_id = ?'
'SELECT last_failure_count FROM user_login_last_failure_count WHERE user_id = ?',
$user->{id}
);

@@ -76,7 +76,7 @@ sub user_locked {
sub ip_banned {
my ($self, $ip) = @_;
my $summary = $self->db->select_row(
'SELECT last_failure_count FROM ip_login_failure_count WHERE ip = ?'
'SELECT last_failure_count FROM ip_login_last_failure_count WHERE ip = ?',
$ip
);

@@ -212,7 +212,7 @@ sub login_log {

# user_locked用のfailure_countサマリー
# - insert or update ...
{
if ($user_id) {
my $user_login_summary = $self->db->select_row(
'SELECT user_id FROM user_login_last_failure_count WHERE user_id = ?',
$user_id
@@ -225,7 +225,7 @@ sub login_log {
}
else {
$self->db->query(
'INSERT INTO user_login_last_failure_count (`user_id`) VALUES (?)',
'INSERT INTO user_login_last_failure_count (`user_id`, `last_failure_count`) VALUES (?, 1)',
$user_id,
);
}
@@ -234,7 +234,7 @@ sub login_log {

# ip_banned用のfailure_countサマリー
# - insert or update ...
{
if ($ip) {
my $ip_login_summary = $self->db->select_row(
'SELECT ip FROM ip_login_last_failure_count WHERE ip = ?',
$ip
@@ -247,8 +247,8 @@ sub login_log {
}
else {
$self->db->query(
'INSERT INTO ip_login_last_failure_count (`ip`) VALUES (?)',
$ip,
'INSERT INTO ip_login_last_failure_count (`ip`, `last_failure_count`) VALUES (?, 1)',
$ip
);
}
}
@@ -337,4 +337,82 @@ get '/report' => sub {
});
};

# サマリーの初期データ確保する君
#get '/init_user_login_last_failure_count_not_succeed' => sub {
# my ($self, $c) = @_;
#
# $self->db->query('
# INSERT INTO
# user_login_last_failure_count
# (user_id, last_failure_count)
# SELECT user_id, cnt FROM (
# SELECT
# user_id, MAX(succeeded) as max_succeeded, COUNT(1) as cnt FROM login_log GROUP BY user_id
# ) AS t0
# WHERE
# t0.user_id IS NOT NULL
# AND
# t0.max_succeeded = 0
# ');
#
# my $last_succeeds = $self->db->select_all('
# SELECT
# user_id, MAX(id) AS last_login_id FROM login_log
# WHERE
# user_id IS NOT NULL AND succeeded = 1 GROUP BY user_id'
# );
#
# for my $row (@$last_succeeds) {
# my $count = $self->db->select_one('
# SELECT COUNT(1) AS cnt FROM login_log WHERE user_id = ? AND ? < id', $row->{user_id}, $row->{last_login_id}
# );
#
# $self->db->query(
# 'INSERT INTO user_login_last_failure_count (user_id, last_failure_count) VALUES (?, ?)',
# $row->{user_id}, $count,
# );
# }
#
# $c->render_json(+{});
#};
#
#
#get '/init_ip_login_last_failure_count_not_succeed' => sub {
# my ($self, $c) = @_;
#
# $self->db->query('
# INSERT INTO
# ip_login_last_failure_count
# (ip, last_failure_count)
# SELECT ip, cnt FROM (
# SELECT
# ip, MAX(succeeded) as max_succeeded, COUNT(1) as cnt FROM login_log GROUP BY ip
# ) AS t0
# WHERE
# t0.max_succeeded = 0
# ');
#
# my $last_succeeds = $self->db->select_all('
# SELECT
# ip, MAX(id) AS last_login_id FROM login_log
# WHERE
# succeeded = 1 GROUP BY ip'
# );
#
# for my $row (@$last_succeeds) {
# my $count = $self->db->select_one('
# SELECT COUNT(1) AS cnt FROM login_log WHERE ip = ? AND ? < id', $row->{ip}, $row->{last_login_id}
# );
#
# $self->db->query(
# 'INSERT INTO ip_login_last_failure_count (ip, last_failure_count) VALUES (?, ?)',
# $row->{ip}, $count,
# );
# }
#
# $c->render_json(+{});
#};



1;

Large diffs are not rendered by default.

@@ -16,11 +16,11 @@ CREATE TABLE IF NOT EXISTS `login_log` (

CREATE TABLE IF NOT EXISTS `user_login_last_failure_count` (
`user_id` int PRIMARY KEY,
`last_failure_count` int NOT NULL DEFAULT 0
`last_failure_count` int NOT NULL
) DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `ip_login_last_failure_count` (
`ip` varchar(255) PRIMARY KEY,
`last_failure_count` int NOT NULL DEFAULT 0
`last_failure_count` int NOT NULL
) DEFAULT CHARSET=utf8;

Large diffs are not rendered by default.

0 comments on commit 2daf40a

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