Skip to content

Instantly share code, notes, and snippets.

@dele
Created November 4, 2013 16:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dele/7304868 to your computer and use it in GitHub Desktop.
Save dele/7304868 to your computer and use it in GitHub Desktop.
register
<?php
$action = "signup";
if(isset($_POST['register'])){
if(isset($_POST['username'])){
if($si->validateMinLength($_POST['username'],$_GLOBALS['ACCOUNT']['USERNAME']->MIN) == true && $si->validateMaxLength($_POST['username'],$_GLOBALS['ACCOUNT']['USERNAME']->MAX) == true && $si->validateUsername($_POST['username']) == true){
$sql = "select id from users where username = '".$db->quote_smart($_POST['username'])."'";
$query = $db->query($sql);
$row = $db->fetch_assoc($query);
if(!$row){
$data['username'] = $db->quote_smart(cyr2url($_POST['username']));
}else{
$errorMsg[] = LANG("The username %s is used in another account",array($db->quote_smart($_POST['username'])));
}
}else{
$errorMsg[] = LANG("Username not valid");
}
}
if(isset($_POST['realname'])){
if($si->validateMinLength($_POST['realname'],$_GLOBALS['ACCOUNT']['REALNAME']->MIN) == true && $si->validateMaxLength($_POST['realname'],$_GLOBALS['ACCOUNT']['REALNAME']->MAX) == true){
$data['realname'] = $db->quote_smart($_POST['realname']);
}else{
$errorMsgp[] = LANG("The realname is not valid");
}
}
if(isset($_POST['email'])){
if($si->validateEmail($_POST['email']) == true){
$email = strtoupper($db->quote_smart($_POST['email']));
$sql = "select id from users where email = '{$email}'";
$query = $db->query($sql);
$row = $db->fetch_assoc($query);
if(!$row){
$data['email'] = $db->quote_smart($_POST['email']);
}else{
$errorMsg[] = LANG("The email %s is used in another account",array($db->quote_smart($_POST['email'])));
}
}else{
$errorMsg[] = LANG("Email not valid");
}
}
if(isset($_POST['mobile'])){
if(isset($_POST['mobile']) && is_numeric($_POST['mobile'])){
$data['mobile'] = $db->quote_smart($_POST['mobile']);
}else{
if($_GLOBALS['ACCOUNT']['PHONE'] == 1){
$errorMsg[] = LANG("The mobile number must be valid");
}elseif(!empty($_POST['mobile'])){
$errorMsg[] = LANG("The mobile number must be numeric");
}
}
}
if(!empty($_POST['password'])){
if(isset($_POST['password']) && $si->validateMinLength($_POST['password'],$_GLOBALS['ACCOUNT']['PASSWORD']->MIN) == true && $si->validateMaxLength($_POST['password'],$_GLOBALS['ACCOUNT']['PASSWORD']->MAX) == true){
if(isset($_POST['password']) && isset($_POST['re-password']) && $_POST['password']==$_POST['re-password']){
$data['password'] = sha1(strtoupper($_POST['password'] . ":" . $data['email']));
}else{
$errorMsg[] = LANG("The password must match");
}
}else{
$errorMsg[] = LANG("The password not valid. The min lengh is %s and max is %s",array($_GLOBALS['ACCOUNT']['PASSWORD']->MIN,$_GLOBALS['ACCOUNT']['PASSWORD']->MAX));
}
}else{
$errorMsg[] = LANG("You must set password");
}
$data['ref'] = isset($_COOKIE['ref']) ? $db->quote_smart(strip_tags($_COOKIE['ref'])) : '';
$data['city_id'] = isset($_POST['city_id']) && $si->is_in_option($_POST['city_id'],$cities) == true ? $db->quote_smart($_POST['city_id']) : $city['id'];
$data['subscribe'] = isset($_POST['subscribe']) && $si->is_true($_POST['subscribe']) == true ? 1 : 0;
if(isset($_POST['terms']) && $si->is_true($_POST['terms'])){
$data['terms'] = 1;
}else{
$errorMsg[] = LANG("You must agree to terms and conditions");
}
if(empty($errorMsg)){
$acc = $data;
unset($acc['terms']);
unset($acc['subscribe']);
$acc['recode'] = sha1($time.$_POST['email']);
$acc['active'] = $_GLOBALS['ACCOUNT']['ACTIVE'];
$acc['money'] = $_GLOBALS['ACCOUNT']['BAlANCE'];
$acc['details'] = 0;
$acc['last_login'] = 0;
$acc['ip'] = $_SERVER['REMOTE_ADDR'];
$id = $db->insert("users",$acc);
if($data['subscribe']==1){
$db->insert("users_subscribed",array(
"email" => $acc['email'],
"city_id" => $acc['city_id'],
"active" => 1,
"ip" => $acc['ip'],
"time" => $time,
"sent" => $time,
));
}
if($_GLOBALS['ACCOUNT']['ACTIVATION'] == '1'){
$_SESSION['errorNo'][] = LANG("Congratulations! You are registred sucessfully and you must login in your email and click activation link");
send_mail(5,array(
'link' => SITE . "active/{$id}-{$acc['recode']}.html",
'name' => $data['realname'],
'username' => $data['username'],
'password' => $_POST['password'],
'to' => $data['email'],
));
}else{
$_SESSION['errorNo'][] = LANG("Congratulations! You are registred sucessfully");
send_mail(6,array(
'name' => $data['realname'],
'username' => $data['username'],
'password' => $_POST['password'],
'to' => $data['email'],
));
if($_GLOBALS['ACCOUNT']['AUTO_LOGIN'] == 1){
Check_Login ($data['email'], "", 1 , $id);
}
$si->redirect(SITE . "login.html");
}
}
}
$smarty->assign("data",$data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment