2 #################################################################################
3 ## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
4 ## --------------------------------------------------------------------------- ##
5 ## Filename Account.php ##
6 ## Developed by: Dzoki ##
7 ## License: TravianX Project ##
8 ## Copyright: TravianX (c) 2010-2011. All rights reserved. ##
10 #################################################################################
12 include("Session.php");
18 if(isset($_POST['ft'])) {
19 switch($_POST['ft']) {
33 } if(isset($_GET['code'])) {
34 $_POST['id'] = $_GET['code']; $this->Activate();
37 if($session->logged_in
&& in_array("logout.php",explode("/",$_SERVER['PHP_SELF']))) {
43 private function Signup() {
44 global $database,$form,$mailer,$generator,$session;
45 if(!isset($_POST['name']) ||
$_POST['name'] == "") {
46 $form->addError("name",USRNM_EMPTY
);
49 if(strlen($_POST['name']) < USRNM_MIN_LENGTH
) {
50 $form->addError("name",USRNM_SHORT
);
52 else if(!USRNM_SPECIAL
&& preg_match('/[^0-9A-Za-z]/',$_POST['name'])) {
53 $form->addError("name",USRNM_CHAR
);
55 else if($database->checkExist($_POST['name'],0)) {
56 $form->addError("name",USRNM_TAKEN
);
58 else if($database->checkExist_activate($_POST['name'],0)) {
59 $form->addError("name",USRNM_TAKEN
);
63 if(!isset($_POST['pw']) ||
$_POST['pw'] == "") {
64 $form->addError("pw",PW_EMPTY
);
67 if(strlen($_POST['pw']) < PW_MIN_LENGTH
) {
68 $form->addError("pw",PW_SHORT
);
70 else if($_POST['pw'] == $_POST['name']) {
71 $form->addError("pw",PW_INSECURE
);
74 if(!isset($_POST['email'])) {
75 $form->addError("email",EMAIL_EMPTY
);
78 if(!$this->validEmail($_POST['email'])) {
79 $form->addError("email",EMAIL_INVALID
);
81 else if($database->checkExist($_POST['email'],1)) {
82 $form->addError("email",EMAIL_TAKEN
);
84 else if($database->checkExist_activate($_POST['email'],1)) {
85 $form->addError("email",EMAIL_TAKEN
);
88 if(!isset($_POST['vid'])) {
89 $form->addError("tribe",TRIBE_EMPTY
);
91 if(!isset($_POST['agb'])) {
92 $form->addError("agree",AGREE_ERROR
);
94 if($form->returnErrors() > 0) {
95 $_SESSION['errorarray'] = $form->getErrors();
96 $_SESSION['valuearray'] = $_POST;
98 header("Location: anmelden.php");
102 $act = $generator->generateRandStr(10);
103 $act2 = $generator->generateRandStr(5);
104 $uid = $database->activate($_POST['name'],md5($_POST['pw']),$_POST['email'],$_POST['vid'],$_POST['kid'],$act,$act2);
107 $mailer->sendActivate($_POST['email'],$_POST['name'],$_POST['pw'],$act);
108 header("Location: activate.php?id=$uid&q=$act2");
112 $uid = $database->register($_POST['name'],md5($_POST['pw']),$_POST['email'],$_POST['vid'],$_POST['kid'],$act);
114 setcookie("COOKUSR",$_POST['name'],time()+COOKIE_EXPIRE
,COOKIE_PATH
);
115 setcookie("COOKEMAIL",$_POST['email'],time()+COOKIE_EXPIRE
,COOKIE_PATH
);
117 $database->updateUserField($uid,"act","",1);
118 $this->generateBase($_POST['kid'],$uid,$_POST['name']);
119 header("Location: login.php");
125 private function Activate() {
127 $q = "SELECT * FROM ".TB_PREFIX
."activate where act = '".$_POST['id']."'";
128 $result = mysql_query($q, $database->connection
);
129 $dbarray = mysql_fetch_array($result);
130 if($dbarray['act'] == $_POST['id']) {
131 $uid = $database->register($dbarray['username'],$dbarray['password'],$dbarray['email'],$dbarray['tribe'],$dbarray['location'],"");
133 $database->unreg($dbarray['username']);
134 $this->generateBase($dbarray['kid'],$uid,$dbarray['username']);
135 header("Location: activate.php?e=2");
139 header("Location: activate.php?e=3");
143 private function Unreg() {
145 $q = "SELECT * FROM ".TB_PREFIX
."activate where id = '".$_POST['id']."'";
146 $result = mysql_query($q, $database->connection
);
147 $dbarray = mysql_fetch_array($result);
148 if(md5($_POST['pw']) == $dbarray['password']) {
149 $database->unreg($dbarray['username']);
150 header("Location: anmelden.php");
153 header("Location: activate.php?e=3");
157 private function Login() {
158 global $database,$session,$form;
159 if(!isset($_POST['user']) ||
$_POST['user'] == "") {
160 $form->addError("user",LOGIN_USR_EMPTY
);
162 else if(!$database->checkExist($_POST['user'],0)) {
163 $form->addError("user",USR_NT_FOUND
);
165 if(!isset($_POST['pw']) ||
$_POST['pw'] == "") {
166 $form->addError("pw",LOGIN_PASS_EMPTY
);
168 else if(!$database->login($_POST['user'],$_POST['pw']) && !$database->sitterLogin($_POST['user'],$_POST['pw'])) {
169 $form->addError("pw",LOGIN_PW_ERROR
);
171 if($database->getUserField($_POST['user'],"act",1) != "") {
172 $form->addError("activate",$_POST['user']);
174 if($form->returnErrors() > 0) {
175 $_SESSION['errorarray'] = $form->getErrors();
176 $_SESSION['valuearray'] = $_POST;
178 header("Location: login.php");
181 setcookie("COOKUSR",$_POST['user'],time()+COOKIE_EXPIRE
,COOKIE_PATH
);
182 $database->UpdateOnline("login" ,$_POST['user'],time());
183 $session->login($_POST['user']);
187 private function Logout() {
188 global $session,$database;
189 unset($_SESSION['wid']);
190 $database->activeModify($session->username
,1);
191 $database->UpdateOnline("logout") or die(mysql_error());
195 private function validEmail($email) {
196 $regexp="/^[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}$/i";
197 if ( !preg_match($regexp, $email) ) {
203 function generateBase($kid,$uid,$username) {
204 global $database,$message;
205 //$database->updateUserField($uid,"location","",1);
210 $kid = $_POST['kid'];
213 $wid = $database->generateBase($kid);
214 $database->setFieldTaken($wid);
215 $database->addVillage($wid,$uid,$username,1);
216 $database->addResourceFields($wid,$database->getVillageType($wid));
217 $database->addUnits($wid);
218 $database->addTech($wid);
219 $database->addABTech($wid);
220 $database->updateUserField($uid,"access",USER
,1);
221 $message->sendWelcome($uid,$username);
225 $account = new Account
;