97 lines
1.6 KiB
C++
Executable File
97 lines
1.6 KiB
C++
Executable File
/*
|
|
* 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()
|
|
{
|
|
fun.url = "adduser";
|
|
}
|
|
|
|
|
|
bool AddUser::CheckAddUserVars(const std::string & login, const std::string & pass, const std::string & conf_pass)
|
|
{
|
|
if( login.empty() )
|
|
{
|
|
request->status = WINIX_ERR_LOGIN_EMPTY;
|
|
return false;
|
|
}
|
|
|
|
if( pass != conf_pass )
|
|
{
|
|
request->status = WINIX_ERR_PASSWORDS_DIFFERENT;
|
|
return false;
|
|
}
|
|
|
|
if( pass.size() < config->password_min_size )
|
|
{
|
|
request->status = WINIX_ERR_PASSWORD_TOO_SHORT;
|
|
return false;
|
|
}
|
|
|
|
if( system->users.IsUser(login) )
|
|
{
|
|
request->status = WINIX_ERR_USER_EXISTS;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void AddUser::MakePost()
|
|
{
|
|
User user;
|
|
|
|
const std::string & login = request->PostVar("login");
|
|
const std::string & pass = request->PostVar("password");
|
|
const std::string & conf_pass = request->PostVar("confirmpassword");
|
|
|
|
if( !CheckAddUserVars(login, pass, conf_pass) )
|
|
return;
|
|
|
|
user.name = login;
|
|
user.email = request->PostVar("email");
|
|
|
|
request->status = db->AddUser(user, pass);
|
|
|
|
if( request->status == WINIX_ERR_OK )
|
|
{
|
|
if( system->users.AddUser(user) )
|
|
{
|
|
if( !request->session->puser )
|
|
system->users.LoginUser(user.id, false);
|
|
|
|
log << log2 << "Adduser: added a new user: " << user.name << logend;
|
|
}
|
|
else
|
|
{
|
|
log << log1 << "Adduser: I can't add to system->users: " << user.name
|
|
<< " but the user was added to the db correctly" << logend;
|
|
}
|
|
|
|
system->RedirectToLastItem();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|