Ejemplo n.º 1
0
 public function validate_root_identity($identification_number, $password)
 {
     $CI =& get_instance();
     $CI->load->model('account_model');
     $CI->load->model('account_type_model');
     $admin_account = $CI->account_model->get_admin_account_by_identification_number($identification_number);
     $account_types = $CI->account_type_model->get_all_account_types();
     if (isset($admin_account)) {
         $CI->load->helper('account_helper');
         $password_from_user_encrypted = _password_account_sal(md5($password), $admin_account->email);
         if ($password_from_user_encrypted == $admin_account->password) {
             if ($account_types[$admin_account->account_type_id - 1] == $account_types[3]) {
                 return true;
             }
         }
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * Create  a Account if the data are accepted or redirect to account View
  */
 public function sign_up()
 {
     $sign_up_form = $this->input->post();
     $notifications = array();
     $session_data = $this->session->all_userdata();
     $categories = $this->get_categories();
     $active_ingredients = $this->get_active_ingredients();
     $data['active_ingredients'] = $active_ingredients;
     if (!isset($session_data['account_types'])) {
         $account_types = $this->account_types->get_account_types();
         $this->session->set_userdata('account_types', $account_types);
     } else {
         $account_types = $session_data['account_types'];
         $data['account_types'] = $session_data['account_types'];
     }
     if (isset($session_data[$account_types[1] . '_id'])) {
         redirect("account/log_in", "refresh");
     }
     $validation_response = $this->_validate_sign_up_form();
     $data['title'] = "Mi cuenta";
     $data['user_logged'] = false;
     $data['categories'] = $categories;
     // breadcrumb start
     $breadcrumb = new stdClass();
     $breadcrumb->title = "Mi cuenta";
     $breadcrumb_item = new stdClass();
     $breadcrumb_item->name = "Mi cuenta";
     $breadcrumb_item->url = "/account";
     $breadcrumb_item->active = true;
     $breadcrumb_list['register'] = $breadcrumb_item;
     $breadcrumb->items = $breadcrumb_list;
     $data['breadcrumb'] = $breadcrumb;
     //breadcrumb over
     if ($validation_response) {
         $userEmail = $sign_up_form['userEmail'];
         //check if exist a account registered with this email
         $account = $this->account_model->get_account_by_email($userEmail);
         if (isset($account)) {
             if ($account->is_ghost == 0) {
                 $message = "Ya existe una cuenta registrada con este email.";
                 if (isset($account->fb_id)) {
                     $message = "Ya existe una cuenta registrada con Facebook, inicia sesión con este.";
                 }
                 $notifications['warning'] = $message;
                 $this->session->set_flashdata('notifications', $notifications);
                 redirect('/account');
             } else {
                 $user_password_encrypted = _password_account_sal(md5($sign_up_form['userPassword']), $userEmail);
                 $sign_up_form['userPassword'] = $user_password_encrypted;
                 $this->account_model->update_account($sign_up_form, $account->id, true);
                 $insert_id = $account->id;
             }
         } else {
             $user_password_encrypted = _password_account_sal(md5($sign_up_form['userPassword']), $userEmail);
             $sign_up_form['userPassword'] = $user_password_encrypted;
             $insert_id = $this->account_model->insert_account($sign_up_form);
             // successfully applied your rules without any of them failing.
         }
         if (isset($insert_id)) {
             // do _log_in
             $account = $this->account_model->get_account_by_id($insert_id);
             if (isset($account->points)) {
                 $data['points'] = $account->points;
             }
             $pathologies = new stdClass();
             $messages = $this->messages->get_every_messages($account->email);
             $account_pathologies = $this->accounts->get_pathologies($insert_id);
             $account_pathologies_dropdown_items_ids = $this->accounts->generate_pathologies_dropdown_items_ids($categories);
             $pathologies->dropdown_items_ids = $account_pathologies_dropdown_items_ids;
             if (isset($messages)) {
                 $messages_sorted = $this->messages->sort_messages($messages, $account->email);
                 $data['messages'] = $messages_sorted;
             }
             $address = $this->addresses->get_sign_up_address($account->id);
             $data['address'] = $address;
             if (isset($account_pathologies)) {
                 $pathologies->account_pathologies = $account_pathologies;
             } else {
                 $pathologies->account_pathologies = null;
             }
             $data['pathologies'] = $pathologies;
             $this->_do_login($account, $data, $account_types);
             $notifications['success'][] = "Tu cuenta a sido creada con éxito, te hemos obsequiado <strong>1000 puntos</strong> que podrás redimir cuando quieras, ¡bienvenido a sanaquefarma!";
             $data['notifications'] = $notifications;
             if (isset($_COOKIE['shoppingcart'])) {
                 $notifications['success'][] = "Los productos en tu carrito de compras están seguros :)!";
                 $this->session->set_flashdata("notifications", $notifications);
                 redirect("/checkout");
             }
             //if ( $account->email == "*****@*****.**" || $account->email == "*****@*****.**" || $account->email == "*****@*****.**" ) {
             $this->mandrill_lib->send_register_email($account);
             //}
             $this->load->view('pages/account-panel', $data);
             // admin account panel
         } else {
             // level('error', 'debug')
             log_message('error', 'insert account not working');
             $notifications['danger'] = "Un evento inesperádo, el administrador de la página será notificádo :(";
             $this->session->set_flashdata('notifications', $notifications);
             redirect("/account");
         }
     } else {
         $notifications['danger'] = validation_errors();
         //print_r($notifications);//check this
         $this->session->set_flashdata('notifications', $notifications);
         //add redirect to account index and show errors
         redirect("/account");
         //you have problems
     }
 }