fake_twitter /app/Controller/UsersController.php

Language PHP Lines 130
MD5 Hash ab6f45eb24aed90f905af7d219094005 Estimated Cost $2,005 (why?)
Repository https://bitbucket.org/udeshika/fake_twitter View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?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';
    }

}

?> 
Back to Top