Changeset 211


Ignore:
Timestamp:
12/29/10 03:04:03 (13 years ago)
Author:
nanardon
Message:
  • add login pages
Location:
server/trunk/web
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Admin.pm

    r188 r211  
    327327} 
    328328 
     329sub set_user_password : XMLRPC { 
     330    my ( $self, $c, $user, $password ) = @_; 
     331 
     332    $c->forward('/user/set_user_password', $user, $password); 
     333} 
     334 
     335sub create_user : XMLRPC { 
     336    my ($self, $c, $user, $password) = @_; 
     337 
     338    if ($c->model('Base::Users')->create({ 
     339            mail => $user, 
     340        })) { 
     341        $c->forward('set_user_password', [ $user, $password ]); 
     342        return $c->stash->{xmlrpc} = "User $user created"; 
     343    } else { 
     344        return; 
     345    } 
     346} 
     347 
    329348=head1 AUTHOR 
    330349 
  • server/trunk/web/lib/Sophie/Controller/Login.pm

    r35 r211  
    2424sub index :Path :Args(0) :XMLRPCPath('/login') { 
    2525    my ( $self, $c, $login, $password ) = @_; 
     26    $login ||= $c->req->param('username'); 
     27    $password ||= $c->req->param('password'); 
    2628 
    27     if ($c->authenticate({ 
    28             mail => $login || $c->req->param('username'), 
    29             password => $password || $c->req->param('password'), 
    30         } 
    31     )) { 
    32         if ($c->req->xmlrpc->is_xmlrpc_request) { 
    33             $c->stash->{xmlrpc} = 'sophie_session=' . $c->sessionid; 
     29    if ($login) { 
     30        if ($c->authenticate({ 
     31                mail => $login, 
     32                password => $password, 
     33            } 
     34        )) { 
     35            if ($c->req->xmlrpc->is_xmlrpc_request) { 
     36                $c->stash->{xmlrpc} = 'sophie_session=' . $c->sessionid; 
     37            } else { 
     38                warn 'redirect'; 
     39                $c->res->redirect($c->uri_for('/')); 
     40            } 
    3441        } else { 
    35             $c->res->redirect('/'); 
    36         } 
    37     } else { 
    38         if ($c->req->xmlrpc->is_xmlrpc_request) { 
    39             $c->error('invalid login / password'); 
     42            if ($c->req->xmlrpc->is_xmlrpc_request) { 
     43                $c->error('invalid login / password'); 
     44            } 
    4045        } 
    4146    } 
    4247} 
    4348 
     49sub create :Local { 
     50    my ($self, $c) = @_; 
     51 
     52    warn $c->req->param('valid'); 
     53    warn $c->session->{valid_create_user}; 
     54    if ((my $valid = $c->req->param('valid')) && $c->req->param('username')) { 
     55       if ($valid == $c->session->{valid_create_user}) { 
     56           my $res = $c->forward('/admin/create_user', 
     57               [ 
     58                   $c->req->param('username'), 
     59                   $c->req->param('password'), 
     60               ] 
     61            ); 
     62            if ($res) { 
     63               $c->res->redirect($c->uri_for('/login', 
     64                   { username => $c->req->param('username') } 
     65               )); 
     66           } 
     67       } 
     68    } 
     69    my $aa = (0 .. 9)[rand(9)]; 
     70    my $bb = (0 .. 9)[rand(9)]; 
     71    $c->stash->{valid} = "$aa + $bb"; 
     72    $c->session->{valid_create_user} = $aa + $bb; 
     73 
     74} 
    4475 
    4576=head1 AUTHOR 
  • server/trunk/web/root/static/sophie.css

    r207 r211  
    252252} 
    253253 
     254div.sophie_auth { 
     255    width: 40%; 
     256    margin: auto; 
     257} 
     258 
     259.sophie_auth label { 
     260    width: 10em; 
     261    display: block; 
     262    float:left; 
     263} 
     264 
     265.sophie_auth input { 
     266} 
     267 
    254268#w3c { 
    255269    float: right; 
  • server/trunk/web/root/templates/html/login/index.html

    r169 r211  
    11<!-- $id$ --> 
     2 
     3<div id="sophie_authenticated" class="sophie_auth"> 
     4<form action="[% c.uri_for('/login') %]" method="POST"> 
     5    <p>Authenticate to Sophie:</p> 
     6    <label for="username">Login:</label> <input type="text" id="username" name="username" value="[% c.req.param('username') %]"><br> 
     7    <label for="passowrd">Password:</label> <input id="password" type="password" name="password" value=""><br> 
     8    <input type="submit"> 
     9</form> 
     10 
     11<p>No account yet: create one <a href="[% c.uri_for('/login/create') 
     12    %]">here</a>.</p> 
     13</div> 
Note: See TracChangeset for help on using the changeset viewer.