mirror of
https://github.com/symkat/MeshMage.git
synced 2024-09-20 14:56:05 +08:00
Add password changing.
This commit is contained in:
parent
8f02da1d08
commit
eef6cbd58c
|
@ -110,14 +110,16 @@ sub startup ($self) {
|
|||
});
|
||||
|
||||
# Controllers to create new things.
|
||||
$auth->get ('/create/network')->to('Create#network' )->name('new_network' );
|
||||
$auth->post('/create/network')->to('Create#create_network')->name('create_network');
|
||||
$auth->get ('/create/node' )->to('Create#node' )->name('new_node' );
|
||||
$auth->post('/create/node' )->to('Create#create_node' )->name('create_node' );
|
||||
$auth->get ('/create/sshkey' )->to('Create#sshkey' )->name('new_sshkey' );
|
||||
$auth->post('/create/sshkey' )->to('Create#create_sshkey' )->name('create_sshkey' );
|
||||
$auth->get ('/create/user' )->to('Create#user' )->name('new_user' );
|
||||
$auth->post('/create/user' )->to('Create#create_user' )->name('create_user' );
|
||||
$auth->get ('/create/network' )->to('Create#network' )->name('new_network' );
|
||||
$auth->post('/create/network' )->to('Create#create_network' )->name('create_network' );
|
||||
$auth->get ('/create/node' )->to('Create#node' )->name('new_node' );
|
||||
$auth->post('/create/node' )->to('Create#create_node' )->name('create_node' );
|
||||
$auth->get ('/create/sshkey' )->to('Create#sshkey' )->name('new_sshkey' );
|
||||
$auth->post('/create/sshkey' )->to('Create#create_sshkey' )->name('create_sshkey' );
|
||||
$auth->get ('/create/user' )->to('Create#user' )->name('new_user' );
|
||||
$auth->post('/create/user' )->to('Create#create_user' )->name('create_user' );
|
||||
$auth->get ('/create/password')->to('Create#password' )->name('new_password' );
|
||||
$auth->post('/create/password')->to('Create#create_password')->name('create_password');
|
||||
|
||||
# Controllers to handle deploying/adopting nodes.
|
||||
$auth->get ('/deploy/manual/:node_id' )->to('Deploy#manual' )->name('deploy_manual' );
|
||||
|
|
|
@ -55,12 +55,18 @@ sub create_login ($c) {
|
|||
my $person = $c->db->resultset('Person')->find( { email => $email } )
|
||||
or push @{$c->stash->{errors}}, "Invalid email address or password.";
|
||||
|
||||
return if $c->stash->{errors};
|
||||
if ( $c->stash->{errors} ) {
|
||||
$c->render( template => 'auth/login' );
|
||||
return 0;
|
||||
}
|
||||
|
||||
$person->auth_password->check_password( $password )
|
||||
or push @{$c->stash->{errors}}, "Invalid email address or password.";
|
||||
|
||||
return if $c->stash->{errors};
|
||||
if ( $c->stash->{errors} ) {
|
||||
$c->render( template => 'auth/login' );
|
||||
return 0;
|
||||
}
|
||||
|
||||
$c->session->{uid} = $person->id;
|
||||
|
||||
|
@ -70,7 +76,6 @@ sub create_login ($c) {
|
|||
sub logout ($c) {
|
||||
undef $c->session->{uid};
|
||||
$c->redirect_to( $c->url_for( 'auth_login' ) );
|
||||
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -173,4 +173,39 @@ sub create_user ($c) {
|
|||
$c->redirect_to( $c->url_for( 'list_users' ) );
|
||||
}
|
||||
|
||||
sub password ($c) {
|
||||
|
||||
}
|
||||
|
||||
sub create_password ($c) {
|
||||
my $old_password = $c->stash->{old_password} = $c->param('old_password');
|
||||
my $password = $c->stash->{password} = $c->param('password');
|
||||
my $password_confirm = $c->stash->{password_confirm} = $c->param('password_confirm');
|
||||
|
||||
push @{$c->stash->{errors}}, "Current password required."
|
||||
unless $old_password;
|
||||
|
||||
push @{$c->stash->{errors}}, "New password required."
|
||||
unless $password;
|
||||
|
||||
push @{$c->stash->{errors}}, "Confirm new password required."
|
||||
unless $password_confirm;
|
||||
|
||||
push @{$c->stash->{errors}}, "Password and confirmation must match."
|
||||
unless $password eq $password_confirm;
|
||||
|
||||
push @{$c->stash->{errors}}, "Your current password was incorrect."
|
||||
unless $c->stash->{person}->auth_password->check_password( $old_password );
|
||||
|
||||
if ( $c->stash->{errors} ) {
|
||||
$c->render( template => 'create/password');
|
||||
return 0;
|
||||
}
|
||||
|
||||
$c->stash->{person}->auth_password->update_password( $password );
|
||||
|
||||
$c->redirect_to( $c->url_for( 'dashboard' )->query( notice => 'password' ) );
|
||||
}
|
||||
|
||||
|
||||
1;
|
||||
|
|
|
@ -42,5 +42,16 @@
|
|||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<h6 class="sidebar-heading d-flex justify-content-between align-items-center px-3 mt-4 mb-1 text-muted">
|
||||
<span>Profile</span>
|
||||
</h6>
|
||||
<ul class="nav flex-column mb-2">
|
||||
<li class="nav-item">
|
||||
<a class="nav-link [% $sb_active == "password" ? "active" : "" %]" href="[% $c.url_for( 'new_password' ) %]">
|
||||
<span data-feather="lock"></span>
|
||||
Change Password
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
<input class="form-control form-control-dark w-100" type="text" placeholder="Search" aria-label="Search">
|
||||
<ul class="navbar-nav px-3">
|
||||
<li class="nav-item text-nowrap"><a class="nav-link" href="[% $c.url_for('logout') %]">Sign out</a></li>
|
||||
</ul>
|
||||
|
|
43
Web/templates/create/password.html.tx
Normal file
43
Web/templates/create/password.html.tx
Normal file
|
@ -0,0 +1,43 @@
|
|||
%% cascade _base::layout { title => "Change Password",
|
||||
%% sb_active => 'password'
|
||||
%% }
|
||||
|
||||
%% override panel -> {
|
||||
|
||||
<h2 style="margin-top: 1.5em" class="h2">Change Password</h2>
|
||||
|
||||
%% if ( $errors.size() ) {
|
||||
<div style="margin-top: 2em" class="alert alert-danger" role="alert">
|
||||
There were errors with your request that could not be resolved:
|
||||
<ul>
|
||||
%% for $errors -> $error {
|
||||
<li>[% $error %]</li>
|
||||
%% }
|
||||
</ul>
|
||||
</div>
|
||||
%% }
|
||||
|
||||
|
||||
<form style="margin-top: 1.5em" method="POST" action="[% $c.url_for( 'create_password' ) %]">
|
||||
|
||||
%% include '_base/form/input.tx' { type => 'password', name => 'old_password',
|
||||
%% title => 'Current Password',
|
||||
%% help => '',
|
||||
%% value => $form_old_password
|
||||
%% };
|
||||
|
||||
%% include '_base/form/input.tx' { type => 'password', name => 'password',
|
||||
%% title => 'New Password',
|
||||
%% help => '',
|
||||
%% value => $form_password
|
||||
%% };
|
||||
|
||||
%% include '_base/form/input.tx' { type => 'password', name => 'password_confirm',
|
||||
%% title => 'Confirm New Password',
|
||||
%% help => '',
|
||||
%% value => $form_password_confirm
|
||||
%% };
|
||||
|
||||
<button type="submit" class="btn btn-primary float-end">Change Password</button>
|
||||
</form>
|
||||
%% }
|
|
@ -17,6 +17,9 @@
|
|||
%% }
|
||||
%% if ( $notice == 'network-created' ) {
|
||||
Your network has been created, it should display below when its certs are generated.
|
||||
%% }
|
||||
%% if ( $notice == 'password' ) {
|
||||
Your password has been updated.
|
||||
%% }
|
||||
</div>
|
||||
%% }
|
||||
|
|
Loading…
Reference in a new issue