2010-08-10 18:12:50 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008-2010, Tomasz Sowa
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "adduser.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Fun
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
AddUser::AddUser()
|
|
|
|
{
|
2010-11-21 01:19:17 +01:00
|
|
|
fun.url = L"adduser";
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-21 01:19:17 +01:00
|
|
|
bool AddUser::CheckAddUserVars(const std::wstring & login, const std::wstring & pass, const std::wstring & conf_pass)
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2010-08-12 21:10:12 +02:00
|
|
|
if( login.empty() )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_LOGIN_EMPTY;
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
if( pass != conf_pass )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_PASSWORDS_DIFFERENT;
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
if( pass.size() < config->password_min_size )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_PASSWORD_TOO_SHORT;
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
if( system->users.IsUser(login) )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = WINIX_ERR_USER_EXISTS;
|
2010-08-10 18:12:50 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AddUser::MakePost()
|
|
|
|
{
|
|
|
|
User user;
|
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
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"confirmpassword");
|
2010-08-10 18:12:50 +02:00
|
|
|
|
|
|
|
if( !CheckAddUserVars(login, pass, conf_pass) )
|
|
|
|
return;
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
user.name = login;
|
2011-01-23 15:15:30 +01:00
|
|
|
user.email = cur->request->PostVar(L"email");
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
cur->request->status = db->AddUser(user, pass);
|
2010-08-10 18:12:50 +02:00
|
|
|
|
2011-01-23 15:15:30 +01:00
|
|
|
if( cur->request->status == WINIX_ERR_OK )
|
2010-08-10 18:12:50 +02:00
|
|
|
{
|
|
|
|
if( system->users.AddUser(user) )
|
|
|
|
{
|
2011-01-23 15:15:30 +01:00
|
|
|
if( !cur->session->puser )
|
2010-08-10 18:12:50 +02:00
|
|
|
system->users.LoginUser(user.id, false);
|
|
|
|
|
2010-08-12 21:10:12 +02:00
|
|
|
log << log2 << "Adduser: added a new user: " << user.name << logend;
|
2010-08-10 18:12:50 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-08-12 21:10:12 +02:00
|
|
|
log << log1 << "Adduser: I can't add to system->users: " << user.name
|
2010-08-10 18:12:50 +02:00
|
|
|
<< " but the user was added to the db correctly" << logend;
|
|
|
|
}
|
|
|
|
|
|
|
|
system->RedirectToLastItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace
|