added: a new winix function: passwd
for changing your password
or if you are a super user you can
change a password for anyone
added: uname prints available plugins now
git-svn-id: svn://ttmath.org/publicrep/winix/trunk@748 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
*/
|
||||
|
||||
#include "adduser.h"
|
||||
#include "core/slog.h"
|
||||
|
||||
|
||||
|
||||
@@ -21,29 +22,65 @@ AddUser::AddUser()
|
||||
}
|
||||
|
||||
|
||||
bool AddUser::CheckAddUserVars(const std::wstring & login, const std::wstring & pass, const std::wstring & conf_pass)
|
||||
/*
|
||||
checking whether login consists of allowed characters
|
||||
currently all characters above 32 (space) are available
|
||||
|
||||
160 - unbreakable space
|
||||
*/
|
||||
bool AddUser::HasLoginCorrectChars(const std::wstring & login)
|
||||
{
|
||||
for(size_t i=0 ; i<login.size() ; ++i)
|
||||
if( login[i] <= 32 || login[i]==160 )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AddUser::IsLoginCorrect(const std::wstring & login)
|
||||
{
|
||||
if( login.empty() )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_LOGIN_EMPTY;
|
||||
log << log3 << "AddUser: login can't be empty" << logend;
|
||||
slog << logerror << T("adduser_err_login_empty") << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( pass != conf_pass )
|
||||
if( !HasLoginCorrectChars(login) )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_PASSWORDS_DIFFERENT;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( pass.size() < config->pass_min_size )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_PASSWORD_TOO_SHORT;
|
||||
log << log3 << "AddUser: incorrect login characters" << logend;
|
||||
slog << logerror << T("adduser_err_login_incorrect_chars") << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( system->users.IsUser(login) )
|
||||
{
|
||||
cur->request->status = WINIX_ERR_USER_EXISTS;
|
||||
log << log3 << "AddUser: such user already exists" << logend;
|
||||
slog << logerror << T("adduser_err_user_exists") << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool AddUser::IsPasswordCorrect(const std::wstring & pass, const std::wstring & conf_pass)
|
||||
{
|
||||
if( pass != conf_pass )
|
||||
{
|
||||
log << log3 << "AddUser: passwords are different" << logend;
|
||||
slog << logerror << T("adduser_err_passwords_different") << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( pass.size() < config->pass_min_size )
|
||||
{
|
||||
log << log3 << "AddUser: password is too small" << logend;
|
||||
slog << logerror << T("adduser_err_password_too_small") << " "
|
||||
<< config->pass_min_size << " " << T("adduser_err_password_too_small2") << logend;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -53,17 +90,14 @@ return true;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void AddUser::MakePost()
|
||||
{
|
||||
User user;
|
||||
|
||||
user.Clear();
|
||||
const std::wstring & login = cur->request->PostVar(L"login");
|
||||
const std::wstring & pass = cur->request->PostVar(L"password");
|
||||
const std::wstring & conf_pass = cur->request->PostVar(L"passwordconfirm");
|
||||
|
||||
if( !CheckAddUserVars(login, pass, conf_pass) )
|
||||
if( !IsLoginCorrect(login) || !IsPasswordCorrect(pass, conf_pass) )
|
||||
return;
|
||||
|
||||
user.name = login;
|
||||
@@ -81,11 +115,11 @@ User user;
|
||||
if( !cur->session->puser )
|
||||
system->users.LoginUser(user.id, false);
|
||||
|
||||
log << log2 << "Adduser: added a new user: " << user.name << logend;
|
||||
log << log2 << "AddUser: added a new user: " << user.name << logend;
|
||||
}
|
||||
else
|
||||
{
|
||||
log << log1 << "Adduser: I can't add to system->users: " << user.name
|
||||
log << log1 << "AddUser: I can't add to system->users: " << user.name
|
||||
<< " but the user was added to the db correctly" << logend;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user