1 %# Add template named 'Password Change', with description
3 %# Automatically generate password for external users who have forgotten their password
10 %# Denne meldingen er automatisk generert som svar på
11 %# din henvendelse, som ekstern bruker av Request Tracker
12 %# ved UiO, om bytte av passord på følgende hjemmeside:
14 %# https://hjelp.uio.no
16 %# For å logge deg på RT bruker du:
17 %# Brukernavn (Username): {$Username}
18 %# Passord (Password): {$Password}
20 %# Har du ellers problemer med din innlogging så sender
23 %# general@hjelp.uio.no
30 <U><B>Glemt passord?/Forgot Your password?</B></U><br>
32 %print $customMessage2;
34 %print $customMessage;
35 <form method="post" action="<% RT->Config->Get('WebPath') %>/NoAuth/Login.html">
36 <input type="text" name="email">
43 use Net::LDAP qw(LDAP_SUCCESS LDAP_PARTIAL_RESULTS);
44 use Net::LDAP::Util qw(ldap_error_name);
49 #my $mailfrom = 'RT reminder <general@hjelp.uio.no>';
52 my $targetType = (GetEmailTypeFromLdap($email) || "none" );
56 if ($targetType !~ /(Sympa|none)/) {
57 $customMessage = "[ You can not change or request a password for an UiO account here. See: <a href=https://brukerinfo.uio.no/>UiO user administration services</a>. ]";
58 $customMessage2 = "[ ERROR: Use your UiO username and password to log in above. ]";
61 my $UserObj = RT::User->new($RT::SystemUser);
62 $UserObj->LoadByEmail($email);
63 if (defined($UserObj->Id)) {
64 my ($val, $str) = ResetPassword($UserObj);
65 $customMessage2 = $str;
69 $customMessage2 = "[ ERROR: No account matches that email address ]";
70 $customMessage = "[ Please enter your email address again ]";
74 $customMessage = "[ Please enter your email address ]";
80 unless ( $self->CurrentUserCanModify('Password') ) {
81 return ( 0, $self->loc("Permission Denied") );
83 my ( $status, $pass ) = $self->SetRandomPassword();
86 return ( 0, "$pass" );
89 my $ret = RT::Interface::Email::SendEmailUsingTemplate(
90 To => $self->EmailAddress,
91 Template => 'Password Change',
94 RealName => $self->RealName,
95 Username => $self->Name
100 return ( 1, $self->loc('[ SUCCESS: New password notification sent to Your email address ]') );
103 return ( 0, $self->loc('[ ERROR: Notification could not be sent ]') );
107 sub GetEmailTypeFromLdap {
109 my $ldap = LdapConnect($RT::LdapServer);
111 my $mesg = $ldap->search (
112 base => $RT::LdapMailBase,
114 filter => "(&(&(objectClass=mailAddr))(mail=$email))",
115 attributes => ["targetType"],
118 if ( ($mesg->code != LDAP_SUCCESS) and
119 ($mesg->code != LDAP_PARTIAL_RESULTS) ) {
120 $RT::Logger->critical("Login-After-Form: Search failed: ",
121 "retval=", $mesg->code, " ",
122 ldap_error_name($mesg->code));
123 LdapDisconnect($ldap);
127 while (my $entry = $mesg->shift_entry) {
128 $targetType = $entry->get_value("targetType");
130 LdapDisconnect($ldap);
135 my $LdapServer = shift;
137 my $ldap = Net::LDAP->new($LdapServer,
140 $RT::Logger->critical("Login-After-Form: Cannot connect to",
141 "LDAP server ", $LdapServer);
145 if ($mesg->code != LDAP_SUCCESS) {
146 $RT::Logger->critical("Login-After-Form: Cannot bind to LDAP: ",
147 "retval=", $mesg->code, " ",
148 ldap_error_name($mesg->code));
156 my $mesg = $ldap->unbind();
157 if ($mesg->code != LDAP_SUCCESS) {
158 $RT::Logger->critical("Login-After-Form: unbind failed: ",
159 "retval=", $mesg->code, " ",
160 ldap_error_name($mesg->code));