12 / 07 / 2009

auth sınıfı kullanımı

ekleyen: Emre Çevik kategori: codeigniter| php| proje

bir önceki yazımızda codeignitere auth sınıfını nasıl entegre edeceğimizi anlatmıştık.
şimdi bu sınıfı nasıl kullanacağımıza bakalım.

Eğer daha önce okumadıysanız auth sınıfı yazısına göz atınız

PROJE DOSYASI

+ parse sınıfı ve kullanımı
+ auth sınıfı ve kullanımı
+ smarty sınıfı ve kullanımı

dosya : 12-07-2009 proje

/project/system/application/controllers/user.php

kayit
Yeni kullanıcı ekleme

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
    function register() {
        if(!LOGIN)
        {
            $this->load->plugin('captcha');
            $send = $this->input->post('savelogin');
 
            $form_submit = true;
            if(empty($send))
            {
                $cap = standart_captcha();
                $this->session->set_userdata('comment_code', $cap['word']);
            }
 
            if(!empty($send))
            {
                $form_submit = $this->auth->validateUser();
                if(!$form_submit)
                {
                    $val = $this->validation;
                    $cap = standart_captcha();
                    $this->session->set_userdata('comment_code', $cap['word']);
                } else {
                    $val = '';
                    $cap['image'] = '';
                    $this->auth->insertUser();
                    $this->session->set_userdata('comment_code', '');
                }
 
            } else$val = '';
 
            $this->theme->assign('cap', $cap['image']);
            $this->theme->assign('validation', $val);
            $this->theme->assign('content', $this->theme->fetch('user/registration_form.tpl'));
            $this->theme->output();
 
        } else $this->profile();
    }
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
<div style="padding:5px">
<form action="/project/index.php/user/register" method="post">
<input type="hidden" name="savelogin" value="no" />
<table style="font-family: Verdana;font-size:11px;width:400px;border: 1px solid #ccc" cellpadding="0" cellspacing="0">
 
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
		{$lang.auth_reg_form}
		</td>
	</tr>
	<tr>
		<td colspan="2" style="background:#8560E8;padding:5px;color:#FFFFFF;font-weight:bold">
			{$lang.auth_login_info}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$lang.general_username}
		</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="text" name="username" value="{$validation->username}" style="width:200px" />
			{$validation->username_error}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$lang.general_email}
		</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="text" name="email" value="{$validation->email}" style="width:200px" />
			{$validation->email_error}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$lang.general_password}
		</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="password" name="password" value="{$validation->password}" style="width:200px" />
			{$validation->password_error}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$lang.auth_re_password}
		</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="password" name="re_password" value="{$validation->re_password}" style="width:200px" />
			{$validation->re_password_error}
		</td>
	</tr>
	<tr>
		<td colspan="2" style="background:#8560E8;padding:5px;color:#FFFFFF;font-weight:bold">
		{$lang.general_security_code}
		</td>
	</tr>
		<tr>
 
		<td colspan="2" valign="top" style="width:400px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$validation->securitycode_error}
			<div style="float:left">{$cap}	</div><div style="padding-top:3px"><input type="text" name="securitycode" value="" style="width:100px" /></div>
 
		</td>
	</tr>
	<tr>
		<td colspan="2" valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="submit" name="" value="Gönder"  />
 
		</td>
	</tr>
</table>
</div>

giris
üye girişi

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
    function login() {
        if(!LOGIN)
        {
            $send = $this->input->post('send');
 
            if(!empty($send))
            {
 
                $form_submit = $this->auth->login();
 
                if(!$form_submit)
                {
                    $val = $this->validation;
                } else {
                    $this->validation->username_error = $this->lang->line('auth_user_no');
                    $val = $this->validation;
                }
 
            } else $val = '';
 
 
            $this->theme->assign('validation', $val);
            $this->theme->assign('content', $this->theme->fetch('user/login_form.tpl'));
            $this->theme->output();
 
        } else $this->profile();
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
<div style="padding:5px">
<form action="/project/index.php/user/login" method="post">
<table style="font-family: Verdana;font-size:11px;width:400px;border: 1px solid #ccc" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="2" style="background:#8560E8;padding:5px;color:#FFFFFF;font-weight:bold">
			{$lang.auth_login_form}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$lang.general_username}
		</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="text" name="username" value="{$validation->username}" style="width:200px" />
			{$validation->username_error}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			{$lang.general_password}
		</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="password" name="password" value="" style="width:200px" />
			{$validation->password_error}
		</td>
	</tr>
 
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">
			<input type="hidden" name="send" value="ok"  />
			<input type="submit" name="" value="Gönder"  />
 
		</td>
	</tr>	
</table>
</form>
</div>

profil

üye profili

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
    function profile() {
        if(LOGIN)
        {
            $send = $this->input->post('send');
            $user_id = U_ID;
 
            $valid = '';
            $form_submit = true;
 
            if(!empty($send))
            {
                $form_submit = $this->auth->validateUserProfile();
                if(!$form_submit) $valid = $this->validation; else $this->auth->setUserProfile($user_id);
            }
 
            $user = $this->auth->getID($user_id);
 
            $this->theme->assign('user', $user);
            $this->theme->assign('validation', $valid);
            $this->theme->assign('content', $this->theme->fetch('user/profile.tpl'));
            $this->theme->output();
 
        } else $this->login();
 
    }
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
<div style="padding:5px">
<form action="{$site_dir}/user/profile" method="post">
<table style="font-family: Verdana;font-size:11px;width:400px;border: 1px solid #ccc" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="2" style="padding:5px;font-size:13px;font-weight:bold">
		{$lang.auth_reg_form}
		</td>
	</tr>
	<tr>
		<td colspan="2" style="background:#8560E8;padding:5px;color:#FFFFFF;font-weight:bold">
			{$lang.auth_login_info}
		</td>
	</tr>
	<tr>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">{$lang.general_username}</td>
		<td valign="top" style="width:200px;padding:5px;border-bottom:1px solid #CCBCF5">{$user->username}</td>
	</tr>
	<tr>
		<td valign="top" style="padding:5px;border-bottom:1px solid #CCBCF5">{$lang.general_email}	</td>
		<td valign="top" style="padding:5px;border-bottom:1px solid #CCBCF5">{$user->email}</td>
	</tr>
 
 
</table>
</div>

üye çıkışı

1
2
3
    function logout() {
        $this->auth->logout();
    }
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • BlinkList
  • blogmarks
  • description
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • Technorati

benzer konular:

  1. auth sınıfı
  2. parse sınıfı
  3. class : codeigniter [ ekle / sil / güncelle ]
  4. observer design pattern – php
  5. smarty
  6. bridge design pattern – php
  7. codeigniter kurulumu
  8. 3 katmanlı mimari ve php -2-
  9. if / else kullanımı
  10. strategy design pattern – php


(3 votes, average: 5.00 out of 5)
Loading ... Loading ...

henüz yorum yazılmadı

yorum yaz

ne yapıyoruz

eğleniyoruz?

anket

design pattern yazılarını nasıl buldunuz?

sonuçlar

Loading ... Loading ...