Beispiel #1
0
 public function Register($params)
 {
     $user = User::Load($params['login']);
     $saved = false;
     if ($user) {
         $user->Set($params);
         $saved = $user->Save();
     } else {
         $user = User::Add($params);
         if ($user) {
             $saved = true;
         }
     }
     if ($saved) {
         header('Location: /Login/UserView/login/' . $user->login, TRUE, 307);
     } else {
         header('Location: /Login/RegisterForm/', TRUE, 307);
     }
 }
Beispiel #2
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     // parse request
     $friendlyId = $request['friendlyId'];
     $name = $request['name'];
     $s_passcode = $request['passcode'];
     $timeZone = $request['timeZone'];
     $email = '';
     $password = '';
     $language = 'en-us';
     // language for the app
     $userId = -1;
     $theme = DEFAULT_THEME;
     // set theme
     if (isset($request['theme'])) {
         $theme = $request['theme'];
     }
     // set language if set
     if (isset($request['language'])) {
         $language = $request['language'];
     }
     // check for email and password
     if (isset($request['email'])) {
         $userLanguage = 'en-us';
         if (isset($request['userLanguage'])) {
             $userLanguage = $request['userLanguage'];
         }
         $email = $request['email'];
         $password = $request['password'];
     } else {
         // get an authuser
         $authUser = new AuthUser();
         if ($authUser->UserUniqId && $authUser->IsSuperAdmin == true) {
             // check if authorized
             $userId = $authUser->UserId;
         } else {
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
     }
     // defaults
     $firstName = 'New';
     $lastName = 'User';
     $domain = APP_URL . '/sites/' . $friendlyId;
     $domain = str_replace('http://', '', $domain);
     $logoUrl = 'sample-logo.png';
     if ($s_passcode == PASSCODE) {
         // check for uniqueness of email
         if ($email != '') {
             $isUserUnique = User::IsLoginUnique($email);
             if ($isUserUnique == false) {
                 return new Tonic\Response(Tonic\Response::CONFLICT);
             }
         }
         $isFriendlyIdUnique = Site::IsFriendlyIdUnique($friendlyId);
         if ($isFriendlyIdUnique == false) {
             return new Tonic\Response(Tonic\Response::CONFLICT);
         }
         // add the site
         $site = Site::Add($domain, $name, $friendlyId, $logoUrl, $theme, $email, $timeZone, $language);
         // add the site
         // add the admin
         if ($email != '') {
             $isActive = 1;
             // admins by default are active
             $user = User::Add($email, $password, $firstName, $lastName, 'Admin', $userLanguage, $isActive, $site['SiteId']);
             $userId = $user['UserId'];
         }
         // set the stripe plan, customer id, status
         if (DEFAULT_STRIPE_PLAN != '') {
             Stripe::setApiKey(STRIPE_API_KEY);
             $customer = Stripe_Customer::create(array("plan" => DEFAULT_STRIPE_PLAN, "email" => $email));
             $customerId = $customer->id;
             Site::EditCustomer($site['SiteUniqId'], $customerId);
         }
         // read the defaults file
         $default_json_file = '../themes/' . $theme . '/default.json';
         // set $siteId
         $siteId = $site['SiteId'];
         // check to make sure the defaults.json exists
         if (file_exists($default_json_file)) {
             // get json from the file
             $json_text = file_get_contents($default_json_file);
             // decode json
             $json = json_decode($json_text, true);
             // pagetypes
             $pagetypes = array();
             // menu counts
             $primaryMenuCount = 0;
             $footerMenuCount = 0;
             // walk through defaults array
             foreach ($json as &$value) {
                 // get values from array
                 $url = $value['url'];
                 $source = $value['source'];
                 $name = $value['name'];
                 $description = $value['description'];
                 $layout = $value['layout'];
                 $stylesheet = $value['stylesheet'];
                 $primaryMenu = $value['primaryMenu'];
                 $footerMenu = $value['footerMenu'];
                 if (strpos($url, '/') !== false) {
                     // the url has a pagetype
                     $arr = explode('/', $url);
                     // get friendly ids from $url
                     $pageTypeFriendlyId = $arr[0];
                     $pageFriendlyId = $arr[1];
                     $pageTypeId = -1;
                     $pageType = PageType::GetByFriendlyId($pageTypeFriendlyId, $siteId);
                     // create a new pagetype
                     if ($pageType == NULL) {
                         $pageType = PageType::Add($pageTypeFriendlyId, 'Page', 'Pages', $layout, $stylesheet, 0, $siteId, $userId, $userId);
                     }
                     // get newly minted page type
                     $pageTypeId = $pageType['PageTypeId'];
                 } else {
                     // root, no pagetype
                     $pageFriendlyId = $url;
                     $pageTypeId = -1;
                 }
                 // create a page
                 $page = Page::Add($pageFriendlyId, $name, $description, $layout, $stylesheet, $pageTypeId, $site['SiteId'], $userId);
                 // set the page to active
                 Page::SetIsActive($page['PageUniqId'], 1);
                 // build the content file
                 $filename = '../themes/' . $theme . '/' . $source;
                 $content = '';
                 // get the content for the page
                 if (file_exists($filename)) {
                     $content = file_get_contents($filename);
                     // fix images
                     $content = str_replace('{{site-dir}}', 'sites/' . $site['FriendlyId'], $content);
                 }
                 // publish the fragment
                 Publish::PublishFragment($site['FriendlyId'], $page['PageUniqId'], 'publish', $content);
                 // build the primary menu
                 if ($primaryMenu == true) {
                     MenuItem::Add($name, '', 'primary', $url, $page['PageId'], $primaryMenuCount, $site['SiteId'], $userId, $userId);
                     $primaryMenuCount++;
                 }
                 // build the footer menu
                 if ($footerMenu == true) {
                     MenuItem::Add($name, '', 'footer', $url, $page['PageId'], $footerMenuCount, $site['SiteId'], $userId, $userId);
                     $footerMenuCount++;
                 }
             }
         } else {
             return new Tonic\Response(Tonic\Response::BADREQUEST);
         }
         // publishes a theme for a site
         Publish::PublishTheme($site, $theme);
         // publish the site
         Publish::PublishSite($site['SiteUniqId']);
         // send welcome email
         if (SEND_WELCOME_EMAIL == true && $email != '') {
             $to = $email;
             $from = REPLY_TO;
             $fromName = REPLY_TO_NAME;
             $subject = BRAND . ': Welcome to ' . BRAND;
             $file = 'emails/new-user.html';
             // create strings to replace
             $loginUrl = APP_URL;
             $newSiteUrl = APP_URL . '/sites/' . $site['FriendlyId'];
             $replace = array('{{brand}}' => BRAND, '{{reply-to}}' => REPLY_TO, '{{new-site-url}}' => $newSiteUrl, '{{login-url}}' => $loginUrl);
             // send email from file
             Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
         }
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Beispiel #3
0
Viewer::AddData("user_name", $user_name);
Viewer::AddData("user_email", $user_email);
if (!empty($user_name) && !empty($user_email) && !empty($_POST["user_password"]) && !empty($_POST["user_password2"])) {
    if ($_POST["user_password"] != $_POST["user_password2"]) {
        $error_message = I18n::L("Passwords mismatch.");
    } else {
        if (!Support::IsEMail($user_email)) {
            $error_message = I18n::L("Wrong E-mail address.");
        } else {
            if (User::FindUser($user_name)) {
                $error_message = I18n::L("Username «%s» is already taken, please find another username.", array($user_name));
            } else {
                if (User::FindUserByEmail($user_email)) {
                    $error_message = I18n::L("This email «%s» is already regesitered, please use another email.", array($user_email));
                } else {
                    $obj = User::Add(User::Create($user_name, $user_email, $_POST["user_password"]));
                    if ($obj->user_id) {
                        Session::StartUser($obj);
                        header("Location:" . PREFIX . "/dashboard/");
                        exit;
                    } else {
                        $error_message = I18n::L("Error while registring user.");
                    }
                    //todo: add some error log
                }
            }
        }
    }
} else {
    if (!empty($_POST["register"])) {
        $error_message = I18n::L("Please fill all required fields.");
Beispiel #4
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     // parse request
     $friendlyId = trim($request['friendlyId']);
     $name = trim($request['name']);
     $s_passcode = $request['passcode'];
     $timeZone = $request['timeZone'];
     $email = '';
     $password = '';
     $language = DEFAULT_LANGUAGE;
     // language for the app
     $direction = DEFAULT_DIRECTION;
     $userId = -1;
     // get first name and lastname
     $firstName = $request['firstName'];
     $lastName = $request['lastName'];
     // validate name and friendlyId
     if ($friendlyId == '' || $name == '') {
         return new Tonic\Response(Tonic\Response::BADREQUEST);
     }
     $theme = DEFAULT_THEME;
     // set theme
     if (isset($request['theme'])) {
         $theme = $request['theme'];
     }
     // set language if set
     if (isset($request['language'])) {
         $language = $request['language'];
     }
     // set direction if set
     if (isset($request['direction'])) {
         $direction = $request['direction'];
     }
     // check for email and password
     if (isset($request['email'])) {
         $userLanguage = 'en-us';
         if (isset($request['userLanguage'])) {
             $userLanguage = $request['userLanguage'];
         }
         $email = $request['email'];
         $password = $request['password'];
         // valide email and password
         if ($email == '' || $password == '') {
             return new Tonic\Response(Tonic\Response::BADREQUEST);
         }
     } else {
         // get an authuser
         $authUser = new AuthUser();
         if ($authUser->UserId && $authUser->IsSuperAdmin == true) {
             // check if authorized
             $userId = $authUser->UserId;
         } else {
             return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
         }
     }
     // defaults
     $domain = SITE_URL;
     $domain = str_replace('{{friendlyId}}', $friendlyId, $domain);
     $logoUrl = 'sample-logo.png';
     $altLogoUrl = '';
     if ($s_passcode == PASSCODE) {
         $isFriendlyIdUnique = Site::IsFriendlyIdUnique($friendlyId);
         // check for reserved names
         if ($friendlyId == 'app' || $friendlyId == 'sites' || $friendlyId == 'api' || $friendlyId == 'triangulate' || $friendlyId == 'developer') {
             $isFriendlyIdUnique = false;
         }
         if ($isFriendlyIdUnique == false) {
             return new Tonic\Response(Tonic\Response::CONFLICT);
         }
         // default is blank
         $welcomeEmail = '';
         $receiptEmail = '';
         // files for emails
         $welcome_file = APP_LOCATION . '/site/emails/welcome.html';
         $receipt_file = APP_LOCATION . '/site/emails/receipt.html';
         // make sure the welcome email exists
         if (file_exists($welcome_file)) {
             // get default email file
             $welcomeEmail = file_get_contents($welcome_file);
         }
         // make sure the receipt email exists
         if (file_exists($receipt_file)) {
             // get default email file
             $receiptEmail = file_get_contents($receipt_file);
         }
         // add the site
         $site = Site::Add($domain, $name, $friendlyId, $logoUrl, $altLogoUrl, $theme, $email, $timeZone, $language, $direction, $welcomeEmail, $receiptEmail);
         // add the admin
         if ($email != '') {
             $isActive = 1;
             // admins by default are active
             $user = User::Add($email, $password, $firstName, $lastName, 'Admin', $userLanguage, $isActive, $site['SiteId']);
             $userId = $user['UserId'];
         }
         // set $siteId
         $siteId = $site['SiteId'];
         // publishes a theme for a site
         Publish::PublishTheme($site, $theme);
         // publish default content for the theme
         Publish::PublishDefaultContent($site, $theme, $user['UserId']);
         // publish the site
         Publish::PublishSite($site['SiteId']);
         // create a locale directory
         $locales_dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/locales';
         // create locales directory if it does not exist
         if (!file_exists($locales_dir)) {
             mkdir($locales_dir, 0755, true);
         }
         // set directory for locale
         $locale_dir = $locales_dir . '/' . $site['Language'] . '/';
         // make the locale dir if it does not exist
         if (!file_exists($locale_dir)) {
             mkdir($locale_dir, 0755, true);
         }
         // set filename
         $filename = 'translation.json';
         if (!file_exists($locale_dir . $filename)) {
             // create a blank translation file
             Utilities::SaveContent($locale_dir, $filename, '{}');
         }
         // send welcome email
         if (SEND_WELCOME_EMAIL == true && $email != '') {
             $to = $email;
             $from = EMAILS_FROM;
             $fromName = EMAILS_FROM_NAME;
             $subject = WELCOME_EMAIL_SUBJECT;
             $file = WELCOME_EMAIL_FILE;
             // create strings to replace
             $loginUrl = APP_URL . '/login/' . $site['FriendlyId'];
             $newSiteUrl = $domain;
             $replace = array('{{brand-logo}}' => '<img src="' . BRAND_LOGO . '" style="max-height:50px">', '{{brand}}' => BRAND, '{{reply-to}}' => EMAILS_FROM, '{{new-site-url}}' => $newSiteUrl, '{{login-url}}' => $loginUrl);
             // send email from file
             Utilities::SendEmailFromFile($to, $from, $fromName, $subject, $replace, $file);
         }
         // send new site hook
         Webhooks::NewSite($site);
         // send new user hook
         Webhooks::NewUser($user);
         return new Tonic\Response(Tonic\Response::OK);
     } else {
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
<?php

require 'user.php';
$USUARIO = $_POST['usuario'];
$Mail = $_POST['mail'];
$Password = $_POST['password'];
$nUser = new User();
$nUser->Add($USUARIO, $Mail, $Password);
Beispiel #6
0
 /**
  * @method POST
  */
 function add()
 {
     // parse request
     parse_str($this->request->data, $request);
     // parse request
     $email = $request['email'];
     $password = $request['password'];
     $firstName = $request['firstName'];
     $lastName = $request['lastName'];
     $role = 'Member';
     $isActive = 0;
     $language = $request['language'];
     $site = Site::GetBySiteUniqId(SITE_UNIQ_ID);
     $user = User::Add($email, $password, $firstName, $lastName, $role, $language, $isActive, $site['SiteId']);
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'applicaton/json';
     $response->body = json_encode($user);
     return $response;
 }
        handleErrorResponse($response);
    }
    echoResponse(SUCCESS_CODE, $response);
});
$app->post("/User/Add/123", function () use($app) {
    require "../src/services/User.php";
    //TODO: check this later include_once dirname(__FILE__) . '../../include/Config.php';
    //  verifyRequiredParams(array("loginname", "password", "deviceid", "ipaddress", "gpscoordinates"));
    //  $userID = $app->request->post("userid");
    //$request = Slim::getInstance()->request();
    $request = $app->request();
    $userData = json_decode($request->post('data'));
    //$userData = json_decode($request->getBody());
    $dataArray = array("email" => $userData->email, "username" => $userData->username, "firstname" => $userData->firstname, "lastname" => $userData->lastname, "password" => $userData->password, "gender" => $userData->gender, "yearOfBirth" => $userData->yearOfBirth, "phone" => $userData->phone, "mobile" => $userData->mobile, "addressLine1" => $userData->addressLine1, "addressLine2" => $userData->addressLine2, "addressCity" => $userData->addressCity, "addressState" => $userData->addressState, "addressCountry" => $userData->addressCountry, "addressZipCode" => $userData->addressZipCode, "photo" => $userData->photo, "interests" => $userData->interests, "newsletters" => $userData->newsletters, "lastLoginTime" => $userData->lastLoginTime, "recordStatus" => $userData->recordStatus, "accountType" => $userData->accountType, "isAdmin" => $userData->isAdmin, "isDataAdmin" => $userData->isDataAdmin, "facebookDetails" => $userData->facebookDetails, "twitterDetails" => $userData->twitterDetails);
    $userObj = new User();
    $response = $userObj->Add($dataArray);
    if ($response == null || $response == FAILED) {
        handleErrorResponse($response);
    }
    echoResponse(SUCCESS_CODE, $response);
});
$app->post("/User/Update/:id", function () use($app) {
    require "../src/services/User.php";
    //TODO: check this later include_once dirname(__FILE__) . '../../include/Config.php';
    //  verifyRequiredParams(array("loginname", "password", "deviceid", "ipaddress", "gpscoordinates"));
    //  $userID = $app->request->post("userid");
    $request = $app->request();
    $userData = json_decode($request->post('data'));
    $id = $userData->id;
    $data = $userData->data;
    $userObj = new User();
Beispiel #8
0
 /**
  * @method POST
  */
 function post()
 {
     parse_str($this->request->data, $request);
     // parse request
     $siteId = $request['siteId'];
     $email = $request['email'];
     $password = $request['password'];
     $firstName = $request['firstName'];
     $lastName = $request['lastName'];
     $role = 'Member';
     // get a reference to the site
     $site = Site::GetBySiteId($siteId);
     // set default language
     $language = $site['Language'];
     $isActive = 0;
     $user = User::Add($email, $password, $firstName, $lastName, $role, $language, $isActive, $siteId);
     // send welcome email
     $subject = SITE_WELCOME_EMAIL_SUBJECT;
     $subject = str_replace('{{site}}', $site['Name'], $subject);
     $content = $site['WelcomeEmail'];
     // send site email
     Utilities::SendSiteEmail($site, $email, $site['PrimaryEmail'], $site['Name'], $subject, $content);
     // return a json response
     $response = new Tonic\Response(Tonic\Response::OK);
     $response->contentType = 'application/json';
     $response->body = json_encode($user);
     return $response;
 }
Beispiel #9
0
            $allOk = false;
        }
    }
    // check password
    if ($password === "") {
        $msgPassword = 'please fill in a password';
        $allOk = false;
    }
    if ($allOk === true) {
        $user = new User();
        $user->first_name = $first_name;
        $user->last_name = $last_name;
        $user->username = $username;
        $user->mail = $mail;
        $user->password = md5($password);
        $user->Add();
        SpoonSession::start();
        SpoonSession::set('id', $user->user_id);
        SpoonHTTP::redirect('dashboard.php');
    }
}
$tpl->assign('first_name', $first_name);
$tpl->assign('last_name', $last_name);
$tpl->assign('username', $username);
$tpl->assign('mail', $mail);
$tpl->assign('password', $password);
$tpl->assign('msgFirst_name', $msgFirst_name);
$tpl->assign('msgLast_name', $msgLast_name);
$tpl->assign('msgUsername', $msgUsername);
$tpl->assign('msgMail', $msgMail);
$tpl->assign('msgPassword', $msgPassword);
Beispiel #10
0
 /**
  * @method POST
  */
 function add()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         parse_str($this->request->data, $request);
         // parse request
         $email = $request['email'];
         $password = $request['password'];
         $firstName = $request['firstName'];
         $lastName = $request['lastName'];
         $role = $request['role'];
         $language = $request['language'];
         $isActive = $request['isActive'];
         $user = User::Add($email, $password, $firstName, $lastName, $role, $language, $isActive, $authUser->SiteId);
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($user);
         return $response;
     } else {
         // unauthorized access
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
<?php

require 'user.php';
$Nam3 = $_POST['nam3'];
$Mail = $_POST['mail'];
$Password = $_POST['password'];
$nUser = new User();
$nUser->Add($Nam3, $Mail, $Password);
echo "<script>alert('Se ha realizado con exito el registro')</script>";
header("Location: index.php");