Skip to content
Browse files

password stuff

  • Loading branch information...
1 parent 5ad97a1 commit 934106534c1992fe98536c08d3d9a293c351aaed @lestrrat lestrrat committed Apr 15, 2009
View
21 core/lib/Pixis/API/MemberAuth.pm
@@ -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';
@@ -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;
View
2 core/lib/Pixis/Web/Controller/Auth.pm
@@ -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} ||
View
37 core/lib/Pixis/Web/Controller/Member.pm
@@ -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) = @_;
@@ -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 {
@@ -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) = @_;
View
26 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
View
5 core/root/member/settings.tt
@@ -7,4 +7,9 @@
[% form %]
</div>
+<h2>パスワード</h2>
+<div class="formbox">
+[% form_password %]
+</div>
+
[% END %]
View
6 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.
Something went wrong with that request. Please try again.