Basic user/session integration
This commit is contained in:
		
							parent
							
								
									5048fb7695
								
							
						
					
					
						commit
						2b6d7fecbb
					
				
					 4 changed files with 108 additions and 22 deletions
				
			
		
							
								
								
									
										22
									
								
								app/initializers/custom-session.js
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								app/initializers/custom-session.js
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,22 @@ | |||
| // from: http://blog.willrax.com/fetching-the-current-user-with-simple-auth/
 | ||||
| import Ember from "ember"; | ||||
| import Session from "simple-auth/session"; | ||||
| 
 | ||||
| export default { | ||||
|   name: "custom-session", | ||||
|   before: "simple-auth", | ||||
|   initialize: function(container) { | ||||
|     Session.reopen({ | ||||
|       setCurrentUser: function() { | ||||
|         var id = this.get("user_id"); | ||||
|         var self = this; | ||||
| 
 | ||||
|         if (!Ember.isEmpty(id)) { | ||||
|           return container.lookup("store:main").find("user", id).then(function(user) { | ||||
|             self.set("currentUser", user); | ||||
|           }); | ||||
|         } | ||||
|       }.observes("user_id") | ||||
|     }); | ||||
|   } | ||||
| }; | ||||
|  | @ -2,25 +2,29 @@ | |||
|     {{#link-to 'index' class='logo'}} | ||||
|       <img src="img/logo.png" width="120"> | ||||
|     {{/link-to}} | ||||
|     <ul> | ||||
|       {{#link-to 'strains' tagName='li' href=false}} | ||||
|         {{#link-to 'strains'}}Strains{{/link-to}} | ||||
|       {{/link-to}} | ||||
|       {{#link-to 'characteristics' tagName='li' href=false}} | ||||
|         {{#link-to 'characteristics'}}Characteristics{{/link-to}} | ||||
|       {{/link-to}} | ||||
|       {{#link-to 'about' tagName='li' href=false}} | ||||
|         {{#link-to 'about'}}About{{/link-to}} | ||||
|       {{/link-to}} | ||||
|     </ul> | ||||
| 
 | ||||
|     <p class="foot"> | ||||
|       {{#if session.isAuthenticated}} | ||||
|     {{#if session.isAuthenticated}} | ||||
|       <ul> | ||||
|         {{#link-to 'strains' tagName='li' href=false}} | ||||
|           {{#link-to 'strains'}}Strains{{/link-to}} | ||||
|         {{/link-to}} | ||||
|         {{#link-to 'characteristics' tagName='li' href=false}} | ||||
|           {{#link-to 'characteristics'}}Characteristics{{/link-to}} | ||||
|         {{/link-to}} | ||||
|         {{#link-to 'about' tagName='li' href=false}} | ||||
|           {{#link-to 'about'}}About{{/link-to}} | ||||
|         {{/link-to}} | ||||
|       </ul> | ||||
|       <p class="foot"> | ||||
|         {{session.currentUser.name}}<br> | ||||
|         <a {{ action 'invalidateSession' }}>Logout</a> | ||||
|       {{else}} | ||||
|         {{#link-to 'login'}}Login{{/link-to}} | ||||
|       {{/if}} | ||||
|     </p> | ||||
|       </p> | ||||
|     {{else}} | ||||
|       <p class="foot"> | ||||
|         {{#link-to 'login' Login}}Login{{/link-to}} | ||||
|         <br> | ||||
|         Sign Up | ||||
|       </p> | ||||
|     {{/if}} | ||||
|   </div> | ||||
| 
 | ||||
|   <div class="flakes-content"> | ||||
|  |  | |||
		Reference in a new issue
	
	 Matthew Dillon
						Matthew Dillon