Skip to content

Commit

Permalink
password stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Apr 15, 2009
1 parent 5ad97a1 commit 9341065
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 1 deletion.
21 changes: 21 additions & 0 deletions core/lib/Pixis/API/MemberAuth.pm
Expand Up @@ -2,6 +2,7 @@ package Pixis::API::MemberAuth;
use Moose;
use Pixis::Registry;
use namespace::clean -except => qw(meta);
use Digest::SHA1 ();

with 'Pixis::API::Base::DBIC';

Expand Down Expand Up @@ -34,6 +35,26 @@ sub load_auth {
return defined $auth ? (wantarray ? @$auth : $auth) : ();
}

sub update_auth {
my ($self, $args) = @_;

$self->resultset->search(
{
member_id => $args->{member_id},
auth_type => $args->{auth_type},
}
)->update(
{
auth_data => Digest::SHA1::sha1_hex($args->{password}),
}
);

my $member = Pixis::Registry->get(api => 'member')->find($args->{member_id});
my $cache_key = [ 'pixis', 'member_auth', $member->email, $args->{auth_type}];

$self->cache_del($cache_key);
}

1;


Expand Down
2 changes: 1 addition & 1 deletion core/lib/Pixis/Web/Controller/Auth.pm
Expand Up @@ -48,7 +48,7 @@ sub login :Local :FormConfig {
if ($form->submitted_and_valid) {
my $auth_ok = $c->forward('/auth/authenticate', [
$form->param('email'), $form->param('password')
] );
] ) && !@{$c->error};
if ($auth_ok) {
$c->res->redirect(
$c->session->{next_uri} ||
Expand Down
37 changes: 37 additions & 0 deletions core/lib/Pixis/Web/Controller/Member.pm
Expand Up @@ -3,7 +3,9 @@
package Pixis::Web::Controller::Member;
use strict;
use warnings;
use utf8;
use base qw(Catalyst::Controller::HTML::FormFu);
use Digest::SHA1 ();

sub auto :Private {
my ($self, $c) = @_;
Expand Down Expand Up @@ -63,6 +65,10 @@ sub settings :Local :Args(0) {
my $user = $c->registry(api => 'Member')->find($c->user->id);
$form->model->default_values($user);
$c->stash->{form} = $form;

$form = $self->form();
$form->load_config_filestem('member/settings_auth');
$c->stash->{form_password} = $form;
}

sub settings_basic :Path('settings/basic') :Args(0) :FormConfig {
Expand All @@ -81,6 +87,37 @@ sub settings_basic :Path('settings/basic') :Args(0) :FormConfig {
}
}

sub settings_auth :Path('settings/auth') :Args(0) :FormConfig {
my ($self, $c) = @_;

my $form = $c->stash->{form};
if ($form->submitted_and_valid) {
my ($auth) = $c->registry(api => 'MemberAuth')->load_auth(
{
email => $c->user->email,
auth_type => 'password'
}
);

my $password = $form->param('password');
my $hashed = unpack('H*', Digest::SHA1->new()->add($password)->digest);
if ($auth->auth_data ne $hashed ) {
$form->form_error_message("現行パスワードが正しくありません");
$form->force_error_message(1);
return;
}

$c->registry(api => 'MemberAuth')->update_auth(
{
member_id => $c->user->id,
auth_type => 'password',
password => $form->param('password_new')
},
);
$c->res->redirect($c->uri_for('/member/settings'));
}
}

sub search :Local :Args(0) :FormConfig {
my ($self, $c) = @_;

Expand Down
26 changes: 26 additions & 0 deletions core/root/forms/member/settings_auth.yaml
@@ -0,0 +1,26 @@
---
auto_fieldset: 1
action: /member/settings/auth
elements:
- type: Password
name: password
label_loc: Password
- type: Password
name: password_new
label_loc: Password (new)
constraints:
- Required
- ASCII
- type: Length
min: 6
max: 24
- type: Password
name: password_check
label_loc: Password (re-type)
constraints:
- Required
- type: Equal
others: password_new
- type: Submit
value: submit
value_loc: Submit
5 changes: 5 additions & 0 deletions core/root/member/settings.tt
Expand Up @@ -7,4 +7,9 @@
[% form %]
</div>

<h2>パスワード</h2>
<div class="formbox">
[% form_password %]
</div>

[% END %]
6 changes: 6 additions & 0 deletions core/root/member/settings_auth.tt
@@ -0,0 +1,6 @@
[% WRAPPER wrapper.tt %]
<h1>パスワードの設定</h1>
<div class="formbox">
[% form %]
</div>
[% END %]

0 comments on commit 9341065

Please sign in to comment.