_binary From 3521f78bb3ba570d077dee36b2575cd6f30bb1dc Mon Sep 17 00:00:00 2001
From: MALLIKA <keertimaantenneti@keertimaan-tennetis-macbook.local>
Date: Mon, 16 Dec 2013 23:32:55 -0800
Subject: [PATCH] Anonymous_account_revised

---
 configs/createdb.php                     |  42 ++++++-
 controllers/admin_controller.php         |  54 +++++++--
 controllers/register_controller.php      | 137 +++++++++++++++++++++
 index.php                                |   8 +-
 models/profile_model.php                 |  16 +--
 models/signin_model.php                  |  71 ++++++++++-
 models/user_model.php                    |  45 ++++++-
 views/elements/configure_element.php     |  13 ++
 views/elements/manageaccount_element.php |  41 ++++++-
 views/register_view.php                  | 196 +++++++++++++++++++++++++++++++
 views/signin_view.php                    |  94 ++++++++-------
 11 files changed, 642 insertions(+), 75 deletions(-)
 create mode 100755 controllers/register_controller.php
 mode change 100644 => 100755 models/profile_model.php
 mode change 100644 => 100755 views/elements/manageaccount_element.php
 create mode 100755 views/register_view.php

diff --git a/configs/createdb.php b/configs/createdb.php
index dd3d415..034fbb2 100755
--- a/configs/createdb.php
+++ b/configs/createdb.php
@@ -84,7 +84,8 @@ if(!$profile_model->createDatabaseTables($db, $dbinfo)) {
 $db->execute("INSERT INTO VERSION VALUES (17)");
 
 //default account is root without a password
-$sql ="INSERT INTO USER VALUES (1, 'root', '".crawlCrypt('')."' ) ";
+$sql ="INSERT INTO USER VALUES (1, 'admin', 'admin','root',
+		'root@dev.null',1,'".crawlCrypt('')."','".crawlCrypt('1')."' ) ";
 $db->execute($sql);
 
 /* we insert 1 by 1 rather than comma separate as sqlite
@@ -124,6 +125,7 @@ foreach($locales as $locale) {
 }
 
 $db->execute("INSERT INTO ROLE VALUES (1, 'Admin' )");
+$db->execute("INSERT INTO ROLE VALUES (2, 'User' )");
 $db->execute("INSERT INTO USER_ROLE VALUES (1, 1)");
 
 $activities = array(
@@ -232,7 +234,8 @@ foreach($activities as $activity => $translation_info) {
     $db->execute("INSERT INTO ACTIVITY VALUES ($i, $i, '$activity')");
     //give admin role the ability to have that activity
     $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (1, $i)");
-    $db->execute("INSERT INTO TRANSLATION VALUES($i,'{$translation_info[0]}')");
+    $db->execute("INSERT INTO TRANSLATION
+            VALUES($i,'{$translation_info[0]}')");
     foreach($translation_info[1] as $locale_tag => $translation) {
         $index = $locale_index[$locale_tag];
         $db->execute("INSERT INTO TRANSLATION_LOCALE VALUES ($i, $index,
@@ -241,6 +244,41 @@ foreach($activities as $activity => $translation_info) {
     $i++;
 }
 
+$new_user_activities = array(
+    "manageAccount" => array('db_activity_manage_account',
+        array(
+            "en-US" => 'Manage Account',
+            "fa" => 'مدیریت حساب',
+            "fr-FR" => 'Modifier votre compte',
+            "ja" => 'アカウント管理',
+            "ko" => '사용자 계정 관리',
+            "vi-VN" => 'Quản lý tài khoản',
+            "zh-CN" => '管理帳號',
+        )),
+    "manageGroups" => array('db_activity_manage_groups',
+        array(
+            "en-US" => 'Manage Groups',
+            "fr-FR" => 'Modifier les groupes',
+        )),
+    "mixCrawls" => array('db_activity_mix_crawls',
+        array(
+            "en-US" => 'Mix Crawls',
+            "fa" => 'ترکیب‌های خزش‌ها',
+            "fr-FR" => 'Mélanger les indexes',
+        )),
+);
+
+foreach($new_user_activities as $new_activity => $translation_info) {
+    $i = 1;
+    foreach($activities as $key => $value) {
+        if($new_activity == $key){
+        //give new user role the ability to have that activity
+            $db->execute("INSERT INTO ROLE_ACTIVITY VALUES (2, $i)");
+        }
+        $i++;
+    }
+}
+
 $db->execute("INSERT INTO MEDIA_SOURCE VALUES ('1342634195',
     'YouTube', 'video', 'http://www.youtube.com/watch?v={}&',
     'http://img.youtube.com/vi/{}/2.jpg', '')");
diff --git a/controllers/admin_controller.php b/controllers/admin_controller.php
index 8f90eb5..1034be6 100755
--- a/controllers/admin_controller.php
+++ b/controllers/admin_controller.php
@@ -85,6 +85,13 @@ class AdminController extends Controller implements CrawlConstants
         "manageClassifiers","resultsEditor", "manageMachines", "manageLocales",
         "crawlStatus","mixCrawls","machineStatus","searchSources","configure");
     /**
+     * Says which activities (roughly methods invoke from the web) this
+     * controller will respond to
+     * @var array
+     */
+    var $new_user_activities = array("manageAccount", "manageGroups",
+        "mixCrawls");
+    /**
      * An array of activities which are periodically updated within other
      * activities that they live. For example, within manage crawl,
      * the current crawl status is updated every 20 or so seconds.
@@ -350,17 +357,20 @@ class AdminController extends Controller implements CrawlConstants
      */
     function manageAccount()
     {
-        $possible_arguments = array("changepassword");
-
+        $possible_arguments = array("changepassword","changeemail");
         $data["ELEMENT"] = "manageaccountElement";
         $data['SCRIPT'] = "";
+        $data['MESSAGE'] = "";
+        $old_email = $this->signinModel->getEmail($_SESSION['USER_ID']);
+        $data["OLD_EMAIL"] = $old_email;
 
         if(isset($_REQUEST['arg']) &&
             in_array($_REQUEST['arg'], $possible_arguments)) {
             switch($_REQUEST['arg'])
             {
                 case "changepassword":
-                    if($_REQUEST['retypepassword'] != $_REQUEST['newpassword']){
+                    if($_REQUEST['re_type_password'] !=
+                            $_REQUEST['new_password']){
                         $data["MESSAGE"] =
                             tl('admin_controller_passwords_dont_match');
                         $data['SCRIPT'] .=
@@ -371,7 +381,7 @@ class AdminController extends Controller implements CrawlConstants
                     $username =
                         $this->signinModel->getUserName($_SESSION['USER_ID']);
                     $result = $this->signinModel->checkValidSignin($username,
-                    $this->clean($_REQUEST['oldpassword'], "string") );
+                    $this->clean($_REQUEST['old_password'], "string") );
                     if(!$result) {
                         $data["MESSAGE"] =
                             tl('admin_controller_invalid_old_password');
@@ -380,14 +390,40 @@ class AdminController extends Controller implements CrawlConstants
                         return $data;
                     }
                     $this->signinModel->changePassword($username,
-                        $this->clean($_REQUEST['newpassword'], "string"));
+                        $this->clean($_REQUEST['new_password'], "string"));
                     $data["MESSAGE"] = tl('admin_controller_change_password');
                     $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
                         $data["MESSAGE"]."</h1>')";
                 break;
-                }
-        }
 
+                case "changeemail":
+                   if($_REQUEST['re_type_email'] != $_REQUEST['new_email']) {
+                        $data["MESSAGE"] =
+                            tl('admin_controller_emails_dont_match');
+                        $data['SCRIPT'] .=
+                            "doMessage('<h1 class=\"red\" >". $data["MESSAGE"].
+                            "</h1>')";
+                        return $data;
+                    }
+                    $username =
+                        $this->signinModel->getUserName($_SESSION['USER_ID']);
+                    $result = $this->signinModel->checkValidEmail($username,
+                    $this->clean($_REQUEST['old_email'], "string") );
+                    if(!$result) {
+                        $data["MESSAGE"] =
+                            tl('admin_controller_invalid_old_email');
+                        $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                            $data["MESSAGE"]."</h1>')";
+                        return $data;
+                    }
+                    $this->signinModel->changeEmail($username,
+                        $this->clean($_REQUEST['new_email'], "string"));
+                    $data["MESSAGE"] = tl('admin_controller_change_email');
+                    $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                        $data["MESSAGE"]."</h1>')";
+                break;
+              }
+        }
         return $data;
     }
 
@@ -3373,8 +3409,8 @@ class AdminController extends Controller implements CrawlConstants
             break;
             case "profile":
                 $this->updateProfileFields($data, $profile,
-                    array('USE_FILECACHE', 'USE_MEMCACHE', "WEB_ACCESS",
-                        'RSS_ACCESS', 'API_ACCESS'));
+                    array('USE_FILECACHE', 'USE_MEMCACHE', "ANONYMOUS_ACCOUNT",
+                        "WEB_ACCESS", 'RSS_ACCESS', 'API_ACCESS'));
                 $data['DEBUG_LEVEL'] = 0;
                 $data['DEBUG_LEVEL'] |=
                     (isset($_REQUEST["ERROR_INFO"])) ? ERROR_INFO : 0;
diff --git a/controllers/register_controller.php b/controllers/register_controller.php
new file mode 100755
index 0000000..08d93e2
--- /dev/null
+++ b/controllers/register_controller.php
@@ -0,0 +1,137 @@
+<?php
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2013  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett chris@pollett.org
+ * @package seek_quarry
+ * @subpackage controller
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2013
+ * @filesource
+ */
+
+if(!defined('BASE_DIR')) {echo "BAD REQUEST"; exit();}
+
+/**
+ *  Load base controller class, if needed
+ */
+require_once BASE_DIR."/controllers/controller.php";
+
+/**
+ * Controller used to handle search requests to SeekQuarry
+ * search site. Used to both get and display
+ * search results.
+ *
+ * @author Mallika Perepa
+ * @package seek_quarry
+ * @subpackage controller
+ */
+class RegisterController extends Controller
+{
+    /**
+     * Load the RegisterView
+     * @var array
+     */
+    var $views = array("register", "search");
+    /**
+     * LocaleModel used to get the available languages/locales, CrawlModel
+     * is used to get a list of available crawls
+     * @var array
+     */
+    var $models = array("user");
+
+    /**
+     *  Allows users to create accounts.
+     *  Validates the input form when creating an account
+     *
+     */
+
+    function processRequest()
+    {
+        $data = array();
+        if(isset($_SESSION['USER_ID'])) {
+            $user = $_SESSION['USER_ID'];
+        } else {
+            $user = $_SERVER['REMOTE_ADDR'];
+        }
+        $data[CSRF_TOKEN] = $this->generateCSRFToken($user);
+        $token_okay = $this->checkCSRFToken(CSRF_TOKEN, $user);
+        $regex_email=
+    '/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/';
+        $data = array();
+        $view = "register";
+        $fields = array("first", "last", "user",
+            "email", "password", "repassword");
+        $data['SCRIPT'] = "";
+        $error = false;
+        if($token_okay && isset($_REQUEST['submit'])) {
+            foreach($fields as $field) {
+                if(empty($_REQUEST[$field]) || !isset($_REQUEST[$field])) {
+                    $error = true;
+                    $data[] = $field;
+                }else if($field == "email" &&
+                    !preg_match($regex_email,
+                    $this->clean($_REQUEST['email'], "string" ))) {
+                        $error = true;
+                        $data[] = "email";
+                }
+            }
+            if(isset($_REQUEST['password'])
+                && isset($_REQUEST['repassword'])
+                && $this->clean($_REQUEST['password'], "string" )!=
+                $this->clean($_REQUEST['repassword'], "string" )){
+                $error = true;
+                $data[] = "password";
+            }
+            if($error) {
+                $data['RESULT'] = "true";
+                $data['FIRST'] = isset($_REQUEST['first']) ?
+                    $this->clean($_REQUEST['first'], "string") : "";
+                $data['LAST'] = isset($_REQUEST['last']) ?
+                    $this->clean($_REQUEST['last'], "string") : "";
+                $data['USER'] = isset($_REQUEST['user']) ?
+                    $this->clean($_REQUEST['user'], "string") : "";
+                $data['EMAIL'] = isset($_REQUEST['email']) ?
+                    $this->clean($_REQUEST['email'], "string") : "";
+                $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                tl('register_controller_error_fields')."</h1>')";
+            } else {
+                $view = "search";
+                $this->userModel->
+                    registerUser($this->clean($_REQUEST['first'], "string" ),
+                    $this->clean($_REQUEST['last'], "string" ),
+                    $this->clean($_REQUEST['user'], "string" ),
+                    $this->clean($_REQUEST['email'], "string" ),
+                    $this->clean($_REQUEST['password'], "string" ));
+                $data['SCRIPT'] .= "doMessage('<h1 class=\"red\" >".
+                tl('register_controller_account_created')."</h1>')";
+            }
+        }
+        $data[CSRF_TOKEN] = $this->generateCSRFToken(
+                $_SERVER['REMOTE_ADDR']);
+        $this->displayView($view, $data);
+    }
+}
+
+?>
diff --git a/index.php b/index.php
index dadfe17..8c56d5f 100755
--- a/index.php
+++ b/index.php
@@ -126,11 +126,11 @@ if (function_exists('lcfirst') === false) {
 }
 
 $available_controllers = array( "admin", "archive",  "cache", "crawl",
-    "fetch",  "machine", "resource", "search", "settings", "statistics",
-    "static", "classifier");
+    "register","fetch",  "machine", "resource", "search", "settings",
+    "statistics", "static", "classifier");
 if(!WEB_ACCESS) {
 $available_controllers = array("admin", "archive", "cache", "crawl", "fetch",
-     "machine");
+     "register", "machine");
 }
 
 //the request variable c is used to determine the controller
@@ -178,7 +178,7 @@ if(file_exists(APP_DIR."/index.php")) {
  */
 if(file_exists(APP_DIR."/controllers/".$controller_name."_controller.php")) {
     require_once(APP_DIR."/controllers/".$controller_name."_controller.php");
-} else {
+} else { 
     require_once(BASE_DIR."/controllers/".$controller_name."_controller.php");
 }
 $controller_class = ucfirst($controller_name)."Controller";
diff --git a/models/profile_model.php b/models/profile_model.php
old mode 100644
new mode 100755
index 7c2d80e..b08a118
--- a/models/profile_model.php
+++ b/models/profile_model.php
@@ -50,8 +50,8 @@ require_once(BASE_DIR.'/lib/url_parser.php');
 class ProfileModel extends Model
 {
     var $profile_fields = array('USER_AGENT_SHORT',
-            'DEFAULT_LOCALE', 'DEBUG_LEVEL', 'DBMS','DB_HOST',
-            'DB_NAME', 'DB_USER', 'DB_PASSWORD',
+            'DEFAULT_LOCALE', 'DEBUG_LEVEL','ANONYMOUS_ACCOUNT','DBMS',
+            'DB_HOST','DB_NAME', 'DB_USER', 'DB_PASSWORD',
             'NAME_SERVER', 'AUTH_KEY', "ROBOT_DESCRIPTION", 'WEB_URI',
             'USE_MEMCACHE', 'MEMCACHE_SERVERS', 'USE_FILECACHE',
             'WORD_SUGGEST', 'CACHE_LINK', 'SIMILAR_LINK',
@@ -270,7 +270,6 @@ EOT;
      *
      * @param object $dbm a DatabaseManager open to some DBMS and with a
      *      blank database selected
-     * @param $dbinfo connection parameters to the database
      * @return bool whether all of the creates were sucessful or not
      */
     function createDatabaseTables($dbm, $dbinfo)
@@ -280,7 +279,9 @@ EOT;
         $create_statements = array(
             "CREATE TABLE VERSION(ID INTEGER PRIMARY KEY)",
             "CREATE TABLE USER(USER_ID INTEGER PRIMARY KEY $auto_increment,
-                USER_NAME VARCHAR(16) UNIQUE,  PASSWORD VARCHAR(16))",
+                FIRST_NAME VARCHAR(16), LAST_NAME VARCHAR(16), 
+                USER_NAME VARCHAR(16) UNIQUE, EMAIL VARCHAR(32),
+                ACTIVE INTEGER,PASSWORD VARCHAR(16), HASH VARCHAR (32))",
             "CREATE TABLE USER_SESSION(USER_ID INTEGER PRIMARY KEY,
                 SESSION VARCHAR(4096))",
             "CREATE TABLE TRANSLATION (TRANSLATION_ID INTEGER PRIMARY KEY
@@ -327,12 +328,13 @@ EOT;
             "CREATE TABLE USER_GROUP (USER_ID INTEGER , GROUP_ID INTEGER,
                    PRIMARY KEY (GROUP_ID, USER_ID) )",
             "CREATE TABLE GROUP_ROLE (GROUP_ID INTEGER , ROLE_ID INTEGER)",
-        );
+            );
         /* NOTE: We are not using singular name GROUP for GROUPS as
            is a reserved SQL keyword
          */
-        foreach($create_statements as $statement) {
-            if(!$dbm->execute($statement)) {return false;}
+        foreach($create_statements as $statement) {;
+            if(!$dbm->execute($statement)) {echo $auto_increment; return false;
+            }
         }
         return true;
     }
diff --git a/models/signin_model.php b/models/signin_model.php
index d7f3814..0cbb4dd 100755
--- a/models/signin_model.php
+++ b/models/signin_model.php
@@ -93,9 +93,34 @@ class SigninModel extends Model
 
         return ($username == $row['USER_NAME'] &&
             crawlCrypt($password, $row['PASSWORD']) == $row['PASSWORD']) ;
-
     }
 
+     /**
+     * Checks that a username email pair is valid
+     *
+     * @param string $username the username to check
+     * @param string $email the email to check
+     * @return bool  where the email is that of the given user
+     *      (or at least hashes to the same thing)
+     */
+
+    function checkValidEmail($username, $email)
+    {
+        $this->db->selectDB(DB_NAME);
+
+        $username = $this->db->escapeString($username);
+        $email = $this->db->escapeString($email);
+            $sql = "SELECT USER_NAME, EMAIL FROM USER ".
+            "WHERE USER_NAME = '$username' LIMIT 1";
+
+        $result = $this->db->execute($sql);
+        if(!$result) {
+            return false;
+        }
+        $row = $this->db->fetchArray($result);
+
+        return ($username == $row['USER_NAME'] && $email == $row['EMAIL']) ;
+    }
 
     /**
      *  Get the user_id associated with a given username
@@ -115,7 +140,6 @@ class SigninModel extends Model
         return $user_id;
     }
 
-
     /**
      *  Get the user_name associated with a given userid
      *
@@ -135,13 +159,52 @@ class SigninModel extends Model
         return $username;
    }
 
+     /**
+     *  Get the email associated with a given userid
+     *
+     *  @param string $user_id the userid to look up
+     *  @return string the corresponding email
+     */
+   function getEmail($user_id, $limit = 1)
+   {
+        $this->db->selectDB(DB_NAME);
+
+        $user_id = $this->db->escapeString($user_id);
+
+        $sql = "SELECT EMAIL FROM USER WHERE
+                    USER_ID = '$user_id' LIMIT $limit";
+        $result = $this->db->execute($sql);
+        $row = $this->db->fetchArray($result);
+        $email = $row['EMAIL'];
+        return $email;
+   }
+
+    /**
+     *  Changes the email of a given user
+     *
+     *  @param string $username username of user to change email of
+     *  @param string $email new email for user
+     *  @return bool update successful or not.
+     */
+
+    function changeEmail($username, $email)
+    {
+        $username = $this->db->escapeString($username);
+        $email = $this->db->escapeString($email);
+
+        $sql = "UPDATE USER SET EMAIL= '$email'
+                    WHERE USER_NAME = '$username' ";
+
+        $result = $this->db->execute($sql);
+        return $result != false;
+    }
 
     /**
      *  Changes the password of a given user
      *
      *  @param string $username username of user to change password of
      *  @param string $password new password for user
-     *  @return boob update successful or not.
+     *  @return bool update successful or not.
      */
     function changePassword($username, $password)
     {
@@ -159,4 +222,4 @@ class SigninModel extends Model
 
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/models/user_model.php b/models/user_model.php
index 16e7293..91e13b6 100755
--- a/models/user_model.php
+++ b/models/user_model.php
@@ -233,6 +233,7 @@ class UserModel extends Model
         return $users;
     }
 
+
     /**
      * Add a user with a given username and password to the list of users
      * that can login to the admin panel
@@ -240,13 +241,49 @@ class UserModel extends Model
      * @param string $username  the username of the user to be added
      * @param string $password  the password of the user to be added
      */
-    function addUser($username, $password)
+    function addUser( $username,$password)
+    {
+        $this->db->selectDB(DB_NAME);
+        $sql = "INSERT INTO USER(USER_NAME, PASSWORD, ACTIVE) VALUES ('".
+          $this->db->escapeString($username)."', '".
+          crawlCrypt($this->db->escapeString($password))."',1 ) ";
+          $result = $this->db->execute($sql);
+    }
+
+    /**
+     * Register a user with firstname, lastname, username, email 
+     *
+     * @param string $firstname the firstname of the user to be added
+     * @param string $lastname the lastname of the user to be added
+     * @param string $username the username of the user to be added
+     * @param string $email the email of the user to be added
+     * @param string $password  the password of the user to be added
+     */
+    function registerUser($firstname, $lastname, $username, $email, $password)
     {
         $this->db->selectDB(DB_NAME);
-        $sql = "INSERT INTO USER(USER_NAME, PASSWORD) VALUES ('".
-            $this->db->escapeString($username)."', '".
-            crawlCrypt($this->db->escapeString($password))."' ) ";
+        $sql = "INSERT INTO USER(FIRST_NAME, LAST_NAME, 
+                USER_NAME, EMAIL,ACTIVE, PASSWORD, HASH) VALUES ('".
+        $this->db->escapeString($firstname)."', '".
+        $this->db->escapeString($lastname)."', '".
+        $this->db->escapeString($username)."', '".
+        $this->db->escapeString($email)."', 1,'".
+            crawlCrypt($this->db->escapeString($password))."','".
+            crawlCrypt($this->db->escapeString($username))."') ";
         $result = $this->db->execute($sql);
+
+        $this->db->selectDB(DB_NAME);
+        $sql = "SELECT USER_ID FROM ".
+            " USER WHERE USER_NAME = '" .
+            $this->db->escapeString($username) . "' ";
+        $result = $this->db->execute($sql);
+        if(!$row = $this->db->fetchArray($result) ) {
+            $last_id = -1;
+        }
+        $last_id = $row['USER_ID'];
+        $sql = "INSERT INTO USER_ROLE  VALUES ('".
+            $this->db->escapeString($last_id)."',2) ";
+        $result_id = $this->db->execute($sql);
     }
 
 
diff --git a/views/elements/configure_element.php b/views/elements/configure_element.php
index 9ea1997..543aaf6 100644
--- a/views/elements/configure_element.php
+++ b/views/elements/configure_element.php
@@ -136,6 +136,19 @@ class ConfigureElement extends Element
                         e("checked='checked'");}?>/><?php
                         e(tl('configure_element_test_info')); ?></label>
             </fieldset>
+            <div class = "top-margin">
+            <fieldset class="extra-wide-field"><legend><?php
+                e(tl('configure_element_user_accounts'))?></legend>
+                <label for="user_accounts"><input
+                    id='user_accounts' type="checkbox"
+                    name="ANONYMOUS_ACCOUNT" value="true"
+                    <?php
+                    if($data['ANONYMOUS_ACCOUNT'] == true) {
+                        e("checked='checked'");
+                    }
+                    ?> /><?php e(tl('configure_element_email_registration'));
+                    ?></label>
+            </fieldset>
             </div>
             <div class="top-margin">
             <fieldset class="extra-wide-field"><legend><?php
diff --git a/views/elements/manageaccount_element.php b/views/elements/manageaccount_element.php
old mode 100644
new mode 100755
index b272f34..13163ee
--- a/views/elements/manageaccount_element.php
+++ b/views/elements/manageaccount_element.php
@@ -54,6 +54,39 @@ class ManageaccountElement extends Element
     function render($data)
     {?>
         <div class="current-activity">
+            <h2><?php e(tl('manageaccount_element_change_email'))?></h2>
+            <form id="changePasswordForm" method="post" action='#'>
+            <input type="hidden" name="c" value="admin" />
+            <input type="hidden" name="<?php e(CSRF_TOKEN); ?>" value="<?php
+                e($data[CSRF_TOKEN]); ?>" />
+            <input type="hidden" name="a" value="manageAccount" />
+            <input type="hidden" name="arg" value="changeemail" />
+
+            <table class="name-table">
+            <tr><td><label for="old-email"><?php
+                e(tl('manageaccount_element_old_email'))?></label></td>
+                <td><input type="txt" id="old-email"
+                    name="old_email"  maxlength="80" class="narrow-field"
+                    value = "<?php e($data['OLD_EMAIL']);?>"/>
+                </td></tr>
+            <tr><td><label for="new-email"><?php
+                e(tl('manageaccount_element_new_email'))?></label></td>
+                <td><input type="text" id="new-email"
+                    name="new_email"  maxlength="80" class="narrow-field"/>
+                </td></tr>
+            <tr><td><label for="retype-email"><?php
+                e(tl('manageaccount_element_retype_email'))?></label></td>
+                <td><input type="text" id="retype-email"
+                    name="re_type_email"  maxlength="80"
+                    class="narrow-field" />
+                </td></tr>
+            <tr><td></td>
+                <td class="center"><button
+                    class="button-box" type="submit"><?php
+                    e(tl('manageaccount_element_save')); ?></button></td></tr>
+            </table>
+            </form>
+
             <h2><?php e(tl('manageaccount_element_change_password'))?></h2>
             <form id="changePasswordForm" method="post" action='#'>
             <input type="hidden" name="c" value="admin" />
@@ -66,17 +99,17 @@ class ManageaccountElement extends Element
             <tr><td><label for="old-password"><?php
                 e(tl('manageaccount_element_old_password'))?></label></td>
                 <td><input type="password" id="old-password"
-                    name="oldpassword"  maxlength="80" class="narrow-field"/>
+                    name="old_password"  maxlength="80" class="narrow-field"/>
                 </td></tr>
             <tr><td><label for="new-password"><?php
                 e(tl('manageaccount_element_new_password'))?></label></td>
                 <td><input type="password" id="new-password"
-                    name="newpassword"  maxlength="80" class="narrow-field"/>
+                    name="new_password"  maxlength="80" class="narrow-field"/>
                 </td></tr>
             <tr><td><label for="retype-password"><?php
                 e(tl('manageaccount_element_retype_password'))?></label></td>
-                <td><input type="password" id="retype-password"
-                    name="retypepassword"  maxlength="80"
+                <td><input type="password" id="re-type-password"
+                    name="re_type_password"  maxlength="80"
                     class="narrow-field" />
                 </td></tr>
             <tr><td></td>
diff --git a/views/register_view.php b/views/register_view.php
new file mode 100755
index 0000000..d6c80d4
--- /dev/null
+++ b/views/register_view.php
@@ -0,0 +1,196 @@
+<?php
+/**
+ *  SeekQuarry/Yioop --
+ *  Open Source Pure PHP Search Engine, Crawler, and Indexer
+ *
+ *  Copyright (C) 2009 - 2013  Chris Pollett chris@pollett.org
+ *
+ *  LICENSE:
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ *  END LICENSE
+ *
+ * @author Chris Pollett
+ * @package seek_quarry
+ * @subpackage view
+ * @license http://www.gnu.org/licenses/ GPL3
+ * @link http://www.seekquarry.com/
+ * @copyright 2009 - 2013
+ * @filesource
+ */
+
+if(!defined('BASE_DIR')) {echo "BAD REQUEST"; exit();}
+
+/**
+ * This View is responsible for drawing the login
+ * screen for the admin panel of the Seek Quarry app
+ *
+ * @author Mallika Perepa
+ * @package seek_quarry
+ * @subpackage view
+ */
+
+class RegisterView extends View
+{
+
+    /** This view is drawn on a web layout
+     *  @var string
+     */
+    var $layout = "web";
+
+    /**
+     *  Draws the create account web page.
+     *
+     *  @param array $data  contains the anti CSRF token
+     *  the view
+     */
+    function renderView($data) 
+    {
+        $logo = "resources/yioop.png";
+        if(MOBILE) {
+            $logo = "resources/m-yioop.png";
+        }
+        ?>
+        <div class="landing non-search">
+            <h1 class="logo"><a href="./?<?php
+                e(CSRF_TOKEN."=".$data[CSRF_TOKEN]) ?>"><img
+                src="<?php e($logo); ?>" alt="Yioop!"/></a>
+                <span> - <?php e(tl('register_view_create_account'));
+                ?></span></h1>
+            <form class="user_settings" method="post" action="#">
+                <div class="login">
+                    <table>
+                        <tr>
+                            <td class="table-label"><b>
+                                <label for="firstname"><?php
+                                    e(tl('register_view_firstname'));
+                                ?></label>:</b>
+                            </td>
+                            <td class="table-input">
+                                <?php $first ="";
+                                if(isset($data['FIRST'])) {
+                                    $first = $data['FIRST'];
+                                }?>
+                                <input id="firstname" type="text"
+                                    class="narrow-field" maxlength="80"
+                                    name="first" autocomplete="off"
+                                    value = "<?php e($first); ?>"/>
+                            </td>
+                            <td><?php echo in_array("first", $data)
+                                    ?'<span class="red">*</span>':''; ?></td>
+                        </tr>
+                        <tr>
+                            <td class="table-label"><b>
+                                <label for="lastname"><?php
+                                    e(tl('register_view_lastname'));
+                                ?></label>:</b>
+                            </td>
+                            <td class="table-input">
+                                <?php $last ="";
+                                if(isset($data['LAST'])) {
+                                    $last = $data['LAST'];
+                                }?>
+                                <input id="lastname" type="text"
+                                    class="narrow-field" maxlength="80"
+                                    name="last" autocomplete="off"
+                                    value = "<?php e($last); ?>"/>
+                            </td>
+                            <td><?php echo in_array("last", $data)
+                                     ?'<span class="red">*</span>':'';?></td>
+                        </tr>
+                        <tr>
+                            <td class="table-label"><b><label for="username">
+                                <?php
+                                e(tl('register_view_username')); ?></label>:</b>
+                            </td>
+                            <td class="table-input">
+                                <?php $user ="";
+                                if(isset($data['USER'])) {
+                                    $user = $data['USER'];
+                                }?>
+                                <input id="username" type="text"
+                                    class="narrow-field" maxlength="80"
+                                    name="user" autocomplete="off"
+                                    value = "<?php e($user); ?>"/>
+                            </td>
+                            <td><?php echo in_array("user", $data)
+                                    ?'<span class="red">*</span>':'';?></td>
+                        </tr>
+                        <tr>
+                            <td class="table-label"><b><label for="email"><?php
+                                e(tl('register_view_email')); ?></label>:</b>
+                            </td>
+                            <td class="table-input">
+                                <?php $email ="";
+                                if(isset($data['EMAIL'])) {
+                                    $email = $data['EMAIL'];
+                                }?><input id="email" type="text"
+                                    class="narrow-field" maxlength="80"
+                                    name="email" autocomplete="off"
+                                    value = "<?php e($email); ?>"/>
+                            </td>
+                            <td><?php echo in_array("email", $data)
+                                    ? '<span class="red">*</span>':'';?></td>
+                        </tr>
+                        <tr>
+                            <td class="table-label"><b>
+                                <label for="password"><?php
+                                    e(tl('register_view_password'));
+                                ?></label>:</b>
+                            </td>
+                            <td class="table-input">
+                                <input id="password" type="password"
+                                    class="narrow-field" maxlength="80"
+                                    name="password"/></td>
+                            <td><?php echo in_array("password", $data)
+                                    ? '<span class="red">*</span>':'';?></td>
+                        </tr>
+                        <tr>
+                            <td class="table-label"><b>
+                                <label for="repassword"><?php
+                                     e(tl('register_view_retypepassword'));
+                                ?></label>:</b>
+                            </td>
+                            <td class="table-input">
+                                <input id="repassword" type="password"
+                                    class="narrow-field" maxlength="80"
+                                    name="repassword"/></td>
+                            <td><?php echo in_array("repassword", $data)
+                                    ?'<span class="red">*</span>':'';?></td>
+                        </tr>
+                        <input type="hidden"
+                                name="<?php e(CSRF_TOKEN);?>"
+                                value="<?php e($data[CSRF_TOKEN]); ?>"/>
+                        <tr>
+                            <td></td>
+                            <td class="center">
+                                <button  type="submit" name="submit"
+                                    value="register"><?php
+                                    e(tl('register_create_account'));
+                                ?></button>
+                            </td>
+                        </tr>
+                    </table>
+                </div>
+            </form>
+                <div class="signin-exit"><a href="."><?php
+                    e(tl('signin_view_return_yioop')); ?></a>
+                </div>
+        </div>
+            <div class='landing-spacer'></div>
+    <?php
+        }
+    }
+    ?>
diff --git a/views/signin_view.php b/views/signin_view.php
index 2069b64..842be15 100755
--- a/views/signin_view.php
+++ b/views/signin_view.php
@@ -56,48 +56,60 @@ class SigninView extends View
      *  @param array $data  contains the anti CSRF token
      *  the view
      */
-    function renderView($data) {
-    $logo = "resources/yioop.png";
-    if(MOBILE) {
-        $logo = "resources/m-yioop.png";
-    }
-?>
-<div class="landing non-search">
-<h1 class="logo"><a href="./?<?php e(CSRF_TOKEN."=".$data[CSRF_TOKEN])
-        ?>"><img src="<?php e($logo); ?>" alt="Yioop!"
-        /></a><span> - <?php e(tl('signin_view_signin')); ?></span></h1>
-<form class="user_settings" method="post" action="#">
-<div class="login">
-    <table>
-    <tr>
-    <td class="table-label" ><b><label for="username"><?php
-        e(tl('signin_view_username')); ?></label>:</b></td><td
-            class="table-input"><input id="username" type="text"
-            class="narrow-field" maxlength="80" name="u"/>
-    </td><td></td></tr>
-    <tr>
-    <td class="table-label" ><b><label for="password"><?php
-        e(tl('signin_view_password')); ?></label>:</b></td><td
-        class="table-input"><input id="password" type="password"
-        class="narrow-field" maxlength="80" name="p" /></td>
-    <td><input type="hidden" name="<?php e(CSRF_TOKEN);?>" value="<?php
-        e($data[CSRF_TOKEN]); ?>" />
-    </td>
-    </tr>
-    <tr><td>&nbsp;</td><td class="center">
-    <button  type="submit" name="c" value="admin"><?php
-        e(tl('signin_view_login')); ?></button>
-    </td><td>&nbsp;</td></tr>
-    </table>
-</div>
-</form>
+    function renderView($data)
+    {
+        $logo = "resources/yioop.png";
+        if(MOBILE) {
+            $logo = "resources/m-yioop.png";
+        }
+        ?>
+        <div class="landing non-search">
+            <h1 class="logo"><a href="./?<?php
+                e(CSRF_TOKEN."=".$data[CSRF_TOKEN]) ?>"><img
+                src="<?php e($logo); ?>" alt="Yioop!"/></a>
+                <span> - <?php e(tl('signin_view_signin')); ?></span></h1>
+            <form class="user_settings" method="post" action="#">
+                <div class="login">
+                <table>
+                    <tr>
+                        <td class="table-label" ><b><label for="username"><?php
+                        e(tl('signin_view_username')); ?></label>:</b></td>
+                        <td class="table-input"><input id="username" type="text"
+                            class="narrow-field" maxlength="80" name="u"/></td>
+                        <td></td>
+                    </tr>
+                    <tr>
+                        <td class="table-label" ><b><label for="password"><?php
+                            e(tl('signin_view_password')); ?></label>:</b></td>
+                        <td class="table-input"><input id="password"
+                            type="password" class="narrow-field"
+                            maxlength="80" name="p" /></td>
+                        <td><input type="hidden"
+                            name="<?php e(CSRF_TOKEN);?>" value="<?php
+                            e($data[CSRF_TOKEN]); ?>" />
+                        </td>
+                    </tr>
+                    <tr><td>&nbsp;</td><td class="center">
+                        <button  type="submit" name="c" value="admin"><?php
+                        e(tl('signin_view_login')); ?></button>
+                        </td><td>&nbsp;</td>
+                    </tr>
+                </table>
+            </div>
+        </form>
 
-<div class="signin-exit"><a href="."><?php
-    e(tl('signin_view_return_yioop')); ?></a></div>
-</div>
+        <div class="signin-exit"><a href="."><?php
+            e(tl('signin_view_return_yioop')); ?></a>
+            <?php if(ANONYMOUS_ACCOUNT) {
+                ?><br/><a href="./?c=register&amp;<?php
+                e(CSRF_TOKEN."=".$data[CSRF_TOKEN])?>&amp;"><?php
+                e(tl('signin_view_create_account')); ?></a>
+            <?php }
+        ?></div>
+    </div>
+        <div class='landing-spacer'></div>
 
-<div class='landing-spacer'></div>
-<?php
+        <?php
     }
 }
-?>
\ No newline at end of file
+?>
-- 
1.8.1

