/app/Controller/UsersController.php
PHP | 130 lines | 86 code | 20 blank | 24 comment | 6 complexity | ab6f45eb24aed90f905af7d219094005 MD5 | raw file
- <?php
-
- /*
- Document : fktwitter
- Created on : Dec 26, 2011, 7:12:34 PM
- Author : udeshika
- Description: fktwitter
- */
-
- class UsersController extends AppController {
-
- public $name = 'Users';
- public $helpers = array('Html', 'Form');
- public $components = array('Session');
-
- public function index() {
-
- }
-
- /**
- * login process and login form
- * @access public
- * @param
- * @return none
- */
- public function login() {
- $this->layout = 'register';
- if (empty($this->data) == false) {
-
- if ($this->validate_login($this->data) == 1) {
- $this->Session->write('User', $this->data['username']);
- $this->Session->setFlash('You\'ve successfully logged in.');
- $this->redirect('../twits/stream/everyone');
- exit();
- } else {
- $this->Session->setFlash('Sorry, the information you\'ve entered is incorrect.');
- exit();
- }
- }
- }
-
-
- public function logout() {
- $this->Session->destroy();
- $this->Session->setFlash('You\'ve successfully logged out.');
- $this->redirect('login');
- }
-
- public function view($id) {
- $this->Twits->id = $id;
- $this->set('post', $this->Twits->read());
- }
-
- public function viewall() {
- $results = $this->User->find('all');
- $this->set('users', $results);
- $this->layout = '';
- }
-
-
- /**
- * add new user after jq validations
- * @access public
- * @param unabale to use mysql_real_escape_string without $link
- * @return none
- */
- public function add() {
- $this->layout = '';
- if ($this->request->is('post')) {
- $postdata = $this->request->data;
- $link = mysql_connect('localhost', 'root', 'mypass');
-
- $sql = "INSERT INTO `cake`.`users` (
- `id` ,
- `username` ,
- `password` ,
- `fname` ,
- `lname` ,
- `email` ,
- `location` ,
- `web` ,
- `bio` ,
- `active` ,
- `created` ,
- `modified`,
- `image`
- )
- VALUES (
- NULL ,
- '" . $postdata['username'] . "',
- '" . $postdata['password'] . "',
- '" . $postdata['fname'] . "',
- '" . $postdata['lname'] . "',
- '" . $postdata['email'] . "',
- '" . $postdata['location'] . "',
- '" . $postdata['web'] . "',
- '" . $postdata['bio'] . "',
- '1',
- '',
- '',
- '" . mysql_real_escape_string(file_get_contents($this->params['data']['User']['image']['tmp_name']), $link) . "'
- );";
- $echo = $this->User->query($sql);
- $this->Session->setFlash('Your post has been created.');
- $this->redirect(array('action' => 'login'));
- }
- }
-
-
-
- /**
- * count users with same username
- * @access public
- * @param $login user data array
- * @return $count; number of users with same username
- */
- public function validate_login($login) {
- $count = $this->User->find('count', array(
- 'conditions' => array('User.username' => $login['username'], 'User.password' => $login['password'])
- ));
- return $count;
- }
-
- public function register() {
- $this->layout = 'register';
- }
-
- }
-
- ?>