added: winix function 'account'

code for activating an account has been moved here from Pw
changed: the form for reseting a user's password has been moved
         to 'passwd' winix function (it was in Pw before)




git-svn-id: svn://ttmath.org/publicrep/winix/trunk@926 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
2013-05-16 19:26:44 +00:00
parent 48cdca7549
commit 7c266b85e2
30 changed files with 1261 additions and 1050 deletions

View File

@@ -2,7 +2,7 @@
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2011-2012, Tomasz Sowa
* Copyright (c) 2011-2013, Tomasz Sowa
* All rights reserved.
*
*/
@@ -124,6 +124,127 @@ long user_id;
}
bool Passwd::SetNewPassword(User * puser, bool use_ses_log)
{
bool result = false;
const std::wstring & pass = cur->request->PostVar(L"passwordnew");
const std::wstring & pass_conf = cur->request->PostVar(L"passwordconfirm");
if( IsPasswordCorrect(pass, pass_conf, use_ses_log) )
{
if( ChangePassword(puser->id, pass) )
{
result = true;
if( use_ses_log )
slog << loginfo << T("pw_password_changed") << logend;
}
else
{
if( use_ses_log )
slog << logerror << T("service_unavailable") << logend;
}
}
return result;
}
bool Passwd::ResetPassword(User * puser, long code, bool use_ses_log, bool only_check_access)
{
std::wstring * user_code_str = puser->aenv.GetValue(L"password_change_code");
if( user_code_str )
{
if( Tol(*user_code_str) == code )
{
if( only_check_access )
return true;
else
return SetNewPassword(puser, use_ses_log);
}
else
{
log << log2 << "Passwd: incorrect change password code" << logend;
if( use_ses_log )
slog << logerror << T(L"incorrect_change_password_code") << logend;
}
}
else
{
log << log1 << "Passwd: there is no change password code in admin environment" << logend;
if( use_ses_log )
slog << loginfo << T(L"password_cannot_be_changed") << logend;
}
return false;
}
bool Passwd::ResetPassword(const std::wstring & login, long code, bool use_ses_log, bool only_check_access)
{
bool result = false;
User * puser = system->users.GetUser(login);
if( puser )
{
long t = static_cast<long>(cur->request->start_time);
if( puser->aenv.Long(L"password_change_time") + config->reset_password_code_expiration_time > t )
{
result = ResetPassword(puser, code, use_ses_log, only_check_access);
}
else
{
log << log2 << "Passwd: the code has expired" << logend;
if( use_ses_log )
slog << logerror << T(L"code_expired") << logend;
}
}
else
{
log << log1 << "Passwd: there is no a user: " << login << logend;
}
return result;
}
void Passwd::ResetPassword()
{
const std::wstring & login = cur->request->PostVar(L"login");
long code = Tol(cur->request->PostVar(L"code"));
ResetPassword(login, code, true, false);
system->RedirectToLastItem();
}
void Passwd::ShowResetPasswordForm()
{
const std::wstring & login = cur->request->ParamValue(L"login");
long code = Tol(cur->request->ParamValue(L"code"));
if( !login.empty() )
{
if( !ResetPassword(login, code, true, true) )
system->RedirectToLastItem();
}
else
{
system->RedirectToLastItem();
}
}
/*
if you are a root (super_user) you can change a password for everyone
(the html form has a select option)
@@ -149,8 +270,21 @@ const std::wstring * plogin;
else
log << log1 << "Passwd: there is no such a user: " << *plogin << logend;
}
else
if( cur->request->IsParam(L"resetpassword") )
{
ResetPassword();
}
}
void Passwd::MakeGet()
{
if( cur->request->IsParam(L"resetpassword") )
ShowResetPasswordForm();
}
} // namespace