Yii Framework Forum: login menggunakan 2 form dari 2 tabel - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

login menggunakan 2 form dari 2 tabel Rate Topic: -----

#1 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 17 April 2012 - 02:13 AM

gan ane lagi binggung nih.
ane punya 2 tabel, tabel admin sama tabel user.
nah ane pengen bukin loginnya jadi binggung gan..
karena tabel admin sama user ga mungkin digabung.

ada yang punya saran ga gan?
kalo ane sih maunya form admin langsung di hit di URLnya.
kalo yang user pake form yang dari gii aja..
tolongin ane gan..
makasih para suhu.
maklum newbie..
belajar itu mudah..
0

#2 User is offline   xent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 14-November 10

Posted 17 April 2012 - 03:57 AM

emang bedanya admin ama user apaan ya bang :P
kenapa ga dibuat satu aja?
+----+----------+----------+--------------+
| id | username | password | status_member|
+----+----------+----------+--------------+

status member buat ngebedain apa dia admin ato user biasa
xent

My first app: School Information System
Find error? Post here
My Blog
0

#3 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 17 April 2012 - 05:30 AM

gini nanti user itu harus di approve dulu sama si admin.
jadi kan di tabel user ada id_admin.
nah kalo di jadiin satu, itu tabel jadi ga normal lagi.

ada masukan ga gan?
belajar itu mudah..
0

#4 User is offline   xent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 14-November 10

Posted 17 April 2012 - 11:32 PM

emangnya tabel login isinya apaan ya? apakah informasi user+pass

berdasar dari tabel yg ku buat diatas
tbl user
+----+----------+----------+--------------+---------+
| id | username | password | status_member|  active | {username UNIQUE INDEXES}
+----+----------+----------+--------------+---------+

tbl detail_user
+----------+------+---------+------------+
| username | name | address |  birthdate | {username PK references to user.username}
+----------+------+---------+------------+

form /site/login khusus buat member
form /backend/login khusus buat admin

kalo mau aprove kan tinggal SELECT username WHERE status_member = 'user_biasa' AND active = 0;
xent

My first app: School Information System
Find error? Post here
My Blog
0

#5 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 18 April 2012 - 12:26 AM

tabel admin
+----------+----------+----------+
| id_admin | username | password |
+----------+----------+----------+

tabel user
+--------+----------+----------+----------+--------+
| id_user| id_admin | username | password | status |  
+--------+----------+----------+----------+--------+

id_admin di isi dari tabel admin, status default 0,
kalo udah di approve sama admin, nanti status jadi 1 trus id_admin di tabel user juga di update sama admin yang approve.


belajar itu mudah..
0

#6 User is offline   xent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 14-November 10

Posted 19 April 2012 - 02:22 AM

berarti tar loginnya ada 2 form
misal:
form /site/login khusus buat member
form /backend/login khusus buat admin

site/login kopi aja ke /backend/admin, useridentitynya berarti ada dua yak, khsus admin ama khusus user
xent

My first app: School Information System
Find error? Post here
My Blog
0

#7 User is offline   teguh11 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 129
  • Joined: 13-November 11

Posted 19 April 2012 - 02:30 AM

View Postxent, on 19 April 2012 - 02:22 AM, said:

berarti tar loginnya ada 2 form
misal:
form /site/login khusus buat member
form /backend/login khusus buat admin

site/login kopi aja ke /backend/admin, useridentitynya berarti ada dua yak, khsus admin ama khusus user



udah bisa gan...
hahaha....
belajar itu mudah..
0

#8 User is offline   John_453P 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 24-March 11

Posted 19 November 2012 - 11:07 PM

View Postteguh11, on 19 April 2012 - 02:30 AM, said:

udah bisa gan...
hahaha....
di controllernya kalua gini apanya yg salah ya gan?
    public function actionMyadmin() {
        $model = new LoginForm;

        // if it is ajax validation request
        if (isset($_POST['ajax']) && $_POST['ajax'] === 'login-form') {
            echo CActiveForm::validate($model);
            Yii::app()->end();
        }

        // collect user input data
        if (isset($_POST['LoginForm'])) {
            $model->attributes = $_POST['LoginForm'];
            // validate user input and redirect to the previous page if valid
            if ($model->validate() && $model->login_admin())
                $this->redirect(Yii::app()->user->returnUrl);
        }
        // display the login form
        $this->renderPartial('login_admin', array('model' => $model));
    }


terus di model/LoginForm.php, seperti ini

	public function login_admin()
	{
		if($this->_identity===null)
		{
			$this->_identity=new AdminIdentity($this->username,$this->password);
			$this->_identity->authenticate();
		}
 [ini yg error]-->   	if($this->_identity->errorCode===AdminIdentity::ERROR_NONE)
		{
			$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
			Yii::app()->admin->login($this->_identity,$duration);
			return true;
		}
		else
			return false;
	}


AdminIdentity seperti ini

class Admindentity extends CUserIdentity
{

    private $_id;
    public function authenticate() {
        $record = Admin::model()->findByAttributes(array('username' => $this->username));
        if ($record === null)
            $this->errorCode = self::ERROR_USERNAME_INVALID;
        else if ($record->password !== md5($this->password))
            $this->errorCode = self::ERROR_PASSWORD_INVALID;
        else {
            $this->_id = $record->id_admin;
            $this->errorCode = self::ERROR_NONE;
            $this->setPersistentStates(array(
                'password' => $this->password,
                'username' => $this->username,
            ));
        }
        return !$this->errorCode;
    }

    public function getId() {
        return $this->_id;
    }
}



muncul warning gini gan

Quote

Fatal error: Class 'AdminIdentity' not found in E:\xampp\htdocs\benicekidsbandung\protected\models\LoginForm.php on line 93

tolong koreksinya, apanya yg salah ya?
0

#9 User is offline   xent 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 97
  • Joined: 14-November 10

Posted 24 November 2012 - 08:40 AM

bukannya udah jelas itu kelas AdminIdentity itu ga ada!
perhatikan nama kelas identitas admin yang di posting, (ane tau, tapi di umpetin dulu) :D
xent

My first app: School Information System
Find error? Post here
My Blog
0

#10 User is offline   mr.shadoww 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 07-December 12

Posted 07 December 2012 - 02:57 AM

Admindentity <--- nama class ente gan harusnya --->AdminIdentity
heheh ane juga nubie banget...tar ane numpang" tanya ya disini...salam kenal :P
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users