root/trunk/data/fixtures/init_db.yml

Revision 5, 4.7 kB (checked in by francois, 6 years ago)

fixed wrong code tag in fixtures

Line 
1 SnippetUser:
2   administrator:
3     login:      admin
4     password:   password
5     first_name: Administrator
6     is_admin:   yes   
7   francois:
8     login:      francois
9     password:   symfony
10     first_name: François
11     last_name:  Zaninotto
12   mad_voter:
13     login:      mad
14     password:   voter
15     first_name: Mad
16     last_name:  Voter
17
18 SnippetSnippet:
19   login1:
20     user_id:    francois
21     title:      Data structure for login
22     body: |
23       in config/schema.xml
24        
25       [code xml]
26       <table name="user" phpName="User">
27         <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
28         <column name="login" type="varchar" size="10" />
29         <column name="password" type="varchar" size="10" />
30         <column name="email" type="varchar" size="50" />
31         <column name="first_name" type="varchar" size="50" />
32         <column name="last_name" type="varchar" size="50" />
33         <column name="is_admin" type="boolean" default="0" />
34         <column name="created_at" type="timestamp" />
35       </table>
36       [/code]
37     tags:       login propel database
38    
39   login2:
40     user_id:    francois
41     title:      MyUser for Login
42     body: |
43       in app/frontend/lib/myUser.class.php
44          
45       [code php]
46       class myUser extends sfBasicSecurityUser
47       {
48        
49         public function signIn($user)
50         {
51           $this->setAttribute('user_id', $user->getId(), 'user');
52           $this->setAttribute('login', $user->getlogin(), 'user');
53      
54           $this->setAuthenticated(true);
55      
56           $this->addCredential('user');
57      
58           if ($user->getIsAdmin())
59           {
60             $this->addCredential('admin');
61           }
62         }
63      
64         public function signOut()
65         {
66           $this->getAttributeHolder()->removeNamespace('user');
67      
68           $this->setAuthenticated(false);
69           $this->clearCredentials();
70         } 
71        
72         public function getUserName()
73         {
74           return $this->getAttribute('login', false, 'user');
75         }
76      
77         public function getUserId()
78         {
79           return $this->getAttribute('user_id', false, 'user');
80         } 
81        
82       }
83       [/code] 
84     tags:       login password security
85
86   login3:
87     user_id:    francois
88     title:      Login actions
89     body: |
90       in app/frontend/modules/user/actions/actions.class.php
91      
92       [code php]
93       class userActions extends sfActions
94       {
95         public function executeCreate()
96         {
97         }
98      
99         public function executeAdd()
100         {
101           // Create the new user
102           $user = new User();
103      
104           $user->setLogin($this->getRequestParameter('login'));
105           $user->setPassword($this->getRequestParameter('password'));
106           $user->setEmail($this->getRequestParameter('email'));
107           $user->setFirstName($this->getRequestParameter('first_name'));
108           $user->setLastName($this->getRequestParameter('last_name'));
109      
110           $user->save();
111          
112           // Sign in with this user
113           $this->getUser()->signIn($user);
114          
115           return $this->redirect('@homepage');
116         } 
117        
118         public function executeLogin()
119         {
120           if ($this->getRequest()->getMethod() != sfRequest::POST)
121           {
122             // display the form   
123             return sfView::SUCCESS;
124           }
125           else
126           {   
127             $login = $this->getRequestParameter('login');
128             $password = $this->getRequestParameter('password');
129            
130             if ($user = UserPeer::getAuthenticatedUser($login, $password))
131             {
132                $this->getUser()->signIn($user);
133                return $this->redirect('@homepage');
134             }
135              
136             return sfView::ERROR;
137           }
138         }
139        
140         public function executeLogout()
141         {
142           $this->getUser()->signOut();
143      
144           return $this->redirect('@homepage');
145         }
146          
147        
148         public function handleErrorAdd()
149         {
150           $this->forward('user', 'create');
151         }
152        
153       }
154       [/code]       
155     tags:       login password security action
156
157 SnippetComment:
158   comment1:
159     user_id:     administrator
160     snippet_id:  login2
161     body:        I totally agree 
162    
163   comment2:
164     user_id:     francois
165     snippet_id:  login2
166     body:        It is so good to see that someone understands me
167    
168   comment3:
169     user_id:     administrator
170     snippet_id:  login3
171     body:        Are you sure?
172
173 SnippetVote:
174   vote1:
175     user_id:     mad_voter
176     snippet_id:  login2
177     vote:        3 
178
179   vote2:
180     user_id:     mad_voter
181     snippet_id:  login3
182     vote:        2
183    
184   vote3:
185     user_id:     administrator
186     snippet_id:  login2
187     vote:        5
Note: See TracBrowser for help on using the browser.