Add admin object
This commit is contained in:
@@ -7,14 +7,28 @@ Class {
|
||||
|
||||
{ #category : 'rendering' }
|
||||
TBAdminHeaderComponent >> renderButtonsOn: html [
|
||||
html form: [ self renderDisconnectButtonOn: html ]
|
||||
html form: [
|
||||
self renderDisconnectButtonOn: html.
|
||||
self renderPublicViewButton: html ]
|
||||
]
|
||||
|
||||
{ #category : 'rendering' }
|
||||
TBAdminHeaderComponent >> renderDisconnectButtonOn: html [
|
||||
html formButton beSecondary;
|
||||
callback: [ component goToPostListView ];
|
||||
html formButton
|
||||
beSecondary;
|
||||
callback: [ self session reset ];
|
||||
with: [
|
||||
html text: 'Disconnect'.
|
||||
html span class: 'glyphicon glyphicon-logout' ]
|
||||
]
|
||||
|
||||
{ #category : 'rendering' }
|
||||
TBAdminHeaderComponent >> renderPublicViewButton: html [
|
||||
self session isLogged ifTrue: [
|
||||
html formButton
|
||||
beSecondary;
|
||||
callback: [ component goToPostListView ];
|
||||
with: [
|
||||
html span class: 'glyphicon glyphicon-eye-open'.
|
||||
html text: ' Public View' ] ]
|
||||
]
|
||||
|
@@ -18,6 +18,8 @@ TBApplicationRootComponent class >> initialize [
|
||||
"self initialize"
|
||||
| app |
|
||||
app := WAAdmin register: self asApplicationAt: 'TinyBlog'.
|
||||
app
|
||||
preferenceAt: #sessionClass put: TBSession.
|
||||
app
|
||||
addLibrary: JQDeploymentLibrary;
|
||||
addLibrary: JQUiDeploymentLibrary;
|
||||
|
@@ -36,7 +36,9 @@ TBHeaderComponent >> renderBrandOn: html [
|
||||
|
||||
{ #category : 'rendering' }
|
||||
TBHeaderComponent >> renderButtonsOn: html [
|
||||
self renderModalLoginButtonOn: html
|
||||
self session isLogged
|
||||
ifTrue: [ self renderSimpleAdminButtonOn: html ]
|
||||
ifFalse: [ self renderModalLoginButtonOn: html ]
|
||||
]
|
||||
|
||||
{ #category : 'rendering' }
|
||||
@@ -63,3 +65,14 @@ TBHeaderComponent >> renderModalLoginButtonOn: html [
|
||||
html span class: 'glyphicon glyphicon-lock'.
|
||||
html text: 'Login' ]
|
||||
]
|
||||
|
||||
{ #category : 'rendering' }
|
||||
TBHeaderComponent >> renderSimpleAdminButtonOn: html [
|
||||
html form: [
|
||||
html formButton
|
||||
beSecondary;
|
||||
callback: [ component goToAdministrationView ];
|
||||
with: [
|
||||
html span class: 'glyphicon glyphicon-list-alt'.
|
||||
html text: ' Admin View' ]]
|
||||
]
|
||||
|
@@ -134,7 +134,9 @@ TBPostsListComponent >> renderPostColumnOn: html [
|
||||
|
||||
{ #category : 'as yet unclassified' }
|
||||
TBPostsListComponent >> tryConnectionWithLogin: login andPassword: password [
|
||||
(login = 'admin' and: [ password = 'topsecret' ])
|
||||
ifTrue: [ self goToAdministrationView ]
|
||||
(login = self blog administrator login and: [ (SHA256 hashMessage: password) = self blog administrator password ])
|
||||
ifTrue: [
|
||||
self session currentAdmin: self blog administrator.
|
||||
self goToAdministrationView ]
|
||||
ifFalse: [ self loginErrorOccurred ]
|
||||
]
|
||||
|
33
src/TinyBlog-Components/TBSession.class.st
Normal file
33
src/TinyBlog-Components/TBSession.class.st
Normal file
@@ -0,0 +1,33 @@
|
||||
Class {
|
||||
#name : 'TBSession',
|
||||
#superclass : 'WASession',
|
||||
#instVars : [
|
||||
'currentAdmin'
|
||||
],
|
||||
#category : 'TinyBlog-Components',
|
||||
#package : 'TinyBlog-Components'
|
||||
}
|
||||
|
||||
{ #category : 'accessing' }
|
||||
TBSession >> currentAdmin [
|
||||
|
||||
^ currentAdmin
|
||||
]
|
||||
|
||||
{ #category : 'accessing' }
|
||||
TBSession >> currentAdmin: anObject [
|
||||
|
||||
currentAdmin := anObject
|
||||
]
|
||||
|
||||
{ #category : 'testing' }
|
||||
TBSession >> isLogged [
|
||||
^ self currentAdmin notNil
|
||||
]
|
||||
|
||||
{ #category : 'initialization' }
|
||||
TBSession >> reset [
|
||||
currentAdmin := nil.
|
||||
self requestContext redirectTo: self application url.
|
||||
self unregister
|
||||
]
|
42
src/TinyBlog/TBAdministrator.class.st
Normal file
42
src/TinyBlog/TBAdministrator.class.st
Normal file
@@ -0,0 +1,42 @@
|
||||
Class {
|
||||
#name : 'TBAdministrator',
|
||||
#superclass : 'Object',
|
||||
#instVars : [
|
||||
'login',
|
||||
'password'
|
||||
],
|
||||
#category : 'TinyBlog',
|
||||
#package : 'TinyBlog'
|
||||
}
|
||||
|
||||
{ #category : 'as yet unclassified' }
|
||||
TBAdministrator class >> login: login password: password [
|
||||
^ self new
|
||||
login: login;
|
||||
password: password;
|
||||
yourself
|
||||
]
|
||||
|
||||
{ #category : 'accessing' }
|
||||
TBAdministrator >> login [
|
||||
|
||||
^ login
|
||||
]
|
||||
|
||||
{ #category : 'accessing' }
|
||||
TBAdministrator >> login: anObject [
|
||||
|
||||
login := anObject
|
||||
]
|
||||
|
||||
{ #category : 'accessing' }
|
||||
TBAdministrator >> password [
|
||||
|
||||
^ password
|
||||
]
|
||||
|
||||
{ #category : 'accessing' }
|
||||
TBAdministrator >> password: anObject [
|
||||
|
||||
password := SHA256 hashMessage: anObject
|
||||
]
|
@@ -2,7 +2,8 @@ Class {
|
||||
#name : 'TBBlog',
|
||||
#superclass : 'Object',
|
||||
#instVars : [
|
||||
'posts'
|
||||
'posts',
|
||||
'adminUser'
|
||||
],
|
||||
#category : 'TinyBlog',
|
||||
#package : 'TinyBlog'
|
||||
@@ -38,6 +39,16 @@ TBBlog class >> current [
|
||||
ifEmpty: [ self new save ]
|
||||
]
|
||||
|
||||
{ #category : 'as yet unclassified' }
|
||||
TBBlog class >> defaultAdminLogin [
|
||||
^ 'admin'
|
||||
]
|
||||
|
||||
{ #category : 'as yet unclassified' }
|
||||
TBBlog class >> defaultAdminPassword [
|
||||
^ 'topsecret'
|
||||
]
|
||||
|
||||
{ #category : 'initialization' }
|
||||
TBBlog class >> initialize [
|
||||
self reset
|
||||
@@ -59,6 +70,11 @@ TBBlog class >> reset [
|
||||
self initializeVoyageOnMemoryDB.
|
||||
]
|
||||
|
||||
{ #category : 'as yet unclassified' }
|
||||
TBBlog >> administrator [
|
||||
^ adminUser
|
||||
]
|
||||
|
||||
{ #category : 'reading' }
|
||||
TBBlog >> allBlogPosts [
|
||||
^ posts
|
||||
@@ -84,10 +100,18 @@ TBBlog >> allVisibleBlogPostsFromCategory: aCategory [
|
||||
^ posts select: [ :p | p category = aCategory and: [ p isVisible ] ]
|
||||
]
|
||||
|
||||
{ #category : 'as yet unclassified' }
|
||||
TBBlog >> createAdministrator [
|
||||
^ TBAdministrator
|
||||
login: self class defaultAdminLogin
|
||||
password: self class defaultAdminPassword
|
||||
]
|
||||
|
||||
{ #category : 'initialization' }
|
||||
TBBlog >> initialize [
|
||||
super initialize.
|
||||
posts := OrderedCollection new
|
||||
posts := OrderedCollection new.
|
||||
adminUser := self createAdministrator
|
||||
]
|
||||
|
||||
{ #category : 'deleting' }
|
||||
|
Reference in New Issue
Block a user