Changeset 1640
- Timestamp:
- 01/18/16 23:32:48 (8 years ago)
- Location:
- trunk/LATMOS-Accounts
- Files:
-
- 2 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts/MANIFEST
r1549 r1640 32 32 bin/la-sql-log 33 33 bin/la-sql-rename-host 34 bin/la-sql-reset-passwd 34 35 bin/la-sql-rev 35 36 bin/la-sql-runstat … … 176 177 templates/mail/account_expire.mail 177 178 templates/mail/account_expired_reminder.mail 179 templates/mail/passwordreset.mail 178 180 testdata/acls1 179 181 testdata/acls2 -
trunk/LATMOS-Accounts/bin/la-sql-upgrade.in
r1490 r1640 883 883 884 884 ], 885 } 885 }, 886 { 887 ver => 17, 888 sql => [ 889 q{ 890 CREATE TABLE passwordreset 891 ( 892 -- Hérité(e) from table revisions: rev integer NOT NULL DEFAULT nextval('revisions_rev_seq'::regclass), 893 -- Hérité(e) from table revisions: date timestamp with time zone NOT NULL DEFAULT now(), 894 -- Hérité(e) from table revisions: "create" timestamp with time zone NOT NULL DEFAULT now(), 895 -- Hérité(e) from table revisions: ikey integer NOT NULL DEFAULT nextval('ikey_seq'::regclass), 896 "user" text NOT NULL, 897 id text NOT NULL, 898 CONSTRAINT passwordreset_pkey PRIMARY KEY (id), 899 CONSTRAINT password_reset_user_fkey FOREIGN KEY ("user") 900 REFERENCES "user" (name) MATCH SIMPLE 901 ON UPDATE CASCADE ON DELETE CASCADE 902 ) 903 INHERITS (revisions) 904 WITH ( 905 OIDS=FALSE 906 ); 907 }, 908 ], 909 }, 886 910 ); 887 911 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/User.pm
r1636 r1640 15 15 use LATMOS::Accounts::I18N; 16 16 use Date::Calc; 17 use LATMOS::Accounts::Mail; 17 18 18 19 our $VERSION = (q$Rev$ =~ /^Rev: (\d+) /)[0]; … … 1496 1497 } 1497 1498 1499 =head2 GenPasswordResetId 1500 1501 Return a new id allowing passowrd reset 1502 1503 =cut 1504 1505 sub GenPasswordResetId { 1506 my ($self) = @_; 1507 1508 my $id = LATMOS::Accounts::Utils::genpassword(length => 32); 1509 1510 my $sth = $self->base->db->prepare_cached(q{ 1511 INSERT INTO passwordreset (id, "user") values (?,?) 1512 }); 1513 1514 if ($sth->execute($id, $self->id)) { 1515 return $id; 1516 } else { 1517 return; 1518 } 1519 } 1520 1521 =head2 SendPasswordReset($url) 1522 1523 Generate a password reset Id and the to the user. 1524 1525 C<$url> is the URL where the password can changed (printf forward, the %s is 1526 replaced by the request id) 1527 1528 =cut 1529 1530 sub SendPasswordReset { 1531 my ($self, $url) = @_; 1532 1533 my $id = $self->GenPasswordResetId; 1534 1535 my $mail = $self->get_attributes('mail') or do { 1536 $self->base->log(LA_ERR, "Cannot sent reset password mail: no mail found"); 1537 return; 1538 }; 1539 1540 my %mail = ( 1541 Subject => 'LATMOS: pasword reset', 1542 'X-LATMOS-Reason' => 'Account destruction', 1543 to => $mail, 1544 ); 1545 1546 my $vars = { 1547 url => sprintf($url, $id), 1548 }; 1549 $vars->{id} = $id; 1550 $vars->{obj} = $self; 1551 1552 my $lamail = LATMOS::Accounts::Mail->new( 1553 $self->base->la, 1554 'passwordreset.mail', 1555 ); 1556 1557 if ($lamail->process(\%mail, $vars)) { 1558 $self->base->log(LA_NOTICE, 1559 "Reset password sent to %s for user %s", 1560 $mail{to}, 1561 $self->id, 1562 ); 1563 } 1564 } 1565 1566 =head2 CheckPasswordResetId($id) 1567 1568 Return True if the reset password ID can be found and is less than one day old 1569 1570 =cut 1571 1572 sub CheckPasswordResetId { 1573 my ($self, $id) = @_; 1574 1575 my $sth = $self->base->db->prepare_cached(q{ 1576 SELECT * FROM passwordreset WHERE 1577 "user" = ? and 1578 id = ? and 1579 "create" >= now() - '1 days'::interval 1580 }); 1581 $sth->execute($self->id, $id); 1582 1583 my $res = $sth->fetchrow_hashref; 1584 $sth->finish; 1585 1586 return $res ? 1 : 0; 1587 } 1588 1498 1589 1; 1499 1590
Note: See TracChangeset
for help on using the changeset viewer.