Implement modal login dialog
This commit is contained in:
@@ -43,7 +43,8 @@ TBApplicationRootComponent >> main: aComponent [
|
|||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
TBApplicationRootComponent >> renderContentOn: html [
|
TBApplicationRootComponent >> renderContentOn: html [
|
||||||
html render: main
|
html render: main.
|
||||||
|
SBSDeploymentLibrary addLoadScriptTo: html
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
|
125
src/TinyBlog-Components/TBAuthenticationComponent.class.st
Normal file
125
src/TinyBlog-Components/TBAuthenticationComponent.class.st
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
Class {
|
||||||
|
#name : 'TBAuthenticationComponent',
|
||||||
|
#superclass : 'SBSComponent',
|
||||||
|
#instVars : [
|
||||||
|
'password',
|
||||||
|
'account',
|
||||||
|
'component'
|
||||||
|
],
|
||||||
|
#category : 'TinyBlog-Components',
|
||||||
|
#package : 'TinyBlog-Components'
|
||||||
|
}
|
||||||
|
|
||||||
|
{ #category : 'instance creation' }
|
||||||
|
TBAuthenticationComponent class >> from: aComponent [
|
||||||
|
^ self new
|
||||||
|
component: aComponent;
|
||||||
|
yourself
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBAuthenticationComponent >> account [
|
||||||
|
|
||||||
|
^ account
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBAuthenticationComponent >> account: anObject [
|
||||||
|
|
||||||
|
account := anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBAuthenticationComponent >> component [
|
||||||
|
|
||||||
|
^ component
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBAuthenticationComponent >> component: anObject [
|
||||||
|
|
||||||
|
component := anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBAuthenticationComponent >> password [
|
||||||
|
|
||||||
|
^ password
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'accessing' }
|
||||||
|
TBAuthenticationComponent >> password: anObject [
|
||||||
|
|
||||||
|
password := anObject
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> renderAccountFieldOn: html [
|
||||||
|
html
|
||||||
|
formGroup: [ html label with: 'Account'.
|
||||||
|
html textInput
|
||||||
|
formControl;
|
||||||
|
attributeAt: 'autofocus' put: 'true';
|
||||||
|
callback: [ :value | account := value ];
|
||||||
|
value: account ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> renderBodyOn: html [
|
||||||
|
html
|
||||||
|
modalBody: [
|
||||||
|
html form: [
|
||||||
|
self renderAccountFieldOn: html.
|
||||||
|
self renderPasswordFieldOn: html.
|
||||||
|
html modalFooter: [ self renderButtonsOn: html ] ] ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> renderButtonsOn: html [
|
||||||
|
html formButton
|
||||||
|
beSecondary;
|
||||||
|
dataDismiss: 'modal';
|
||||||
|
value: 'Cancel'.
|
||||||
|
html formButton
|
||||||
|
"beSubmit;"
|
||||||
|
bePrimary;
|
||||||
|
callback: [ self validate ];
|
||||||
|
value: 'SignIn'
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> renderContentOn: html [
|
||||||
|
html modal
|
||||||
|
id: 'myAuthDialog';
|
||||||
|
fade;
|
||||||
|
with: [
|
||||||
|
html modalDialog: [
|
||||||
|
html modalContent: [
|
||||||
|
self renderHeaderOn: html.
|
||||||
|
self renderBodyOn: html ] ] ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> renderHeaderOn: html [
|
||||||
|
html
|
||||||
|
modalHeader: [
|
||||||
|
html modalCloseButton.
|
||||||
|
html modalTitle
|
||||||
|
level: 4;
|
||||||
|
with: 'Authentication' ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> renderPasswordFieldOn: html [
|
||||||
|
html
|
||||||
|
formGroup: [ html label with: 'Password'.
|
||||||
|
html passwordInput
|
||||||
|
formControl;
|
||||||
|
callback: [ :value | password := value ];
|
||||||
|
value: password ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'rendering' }
|
||||||
|
TBAuthenticationComponent >> validate [
|
||||||
|
^ component tryConnectionWithLogin: self account andPassword: self password
|
||||||
|
]
|
@@ -36,7 +36,7 @@ TBHeaderComponent >> renderBrandOn: html [
|
|||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
TBHeaderComponent >> renderButtonsOn: html [
|
TBHeaderComponent >> renderButtonsOn: html [
|
||||||
self renderSimpleAdminButtonOn: html
|
self renderModalLoginButtonOn: html
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
@@ -54,11 +54,12 @@ TBHeaderComponent >> renderContentOn: html [
|
|||||||
]
|
]
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
TBHeaderComponent >> renderSimpleAdminButtonOn: html [
|
TBHeaderComponent >> renderModalLoginButtonOn: html [
|
||||||
html form: [
|
html render: (TBAuthenticationComponent from: component).
|
||||||
html formButton beSecondary;
|
html formButton beSecondary;
|
||||||
callback: [ component goToAdministrationView ];
|
dataTarget: '#myAuthDialog';
|
||||||
|
dataToggle: 'modal';
|
||||||
with: [
|
with: [
|
||||||
html span class: 'glyphicon glyphicon-list-alt'.
|
html span class: 'glyphicon glyphicon-lock'.
|
||||||
html text: 'Admin View' ] ]
|
html text: 'Login' ]
|
||||||
]
|
]
|
||||||
|
@@ -3,7 +3,8 @@ Class {
|
|||||||
#superclass : 'TBScreenComponent',
|
#superclass : 'TBScreenComponent',
|
||||||
#instVars : [
|
#instVars : [
|
||||||
'postComponents',
|
'postComponents',
|
||||||
'currentCategory'
|
'currentCategory',
|
||||||
|
'showLoginError'
|
||||||
],
|
],
|
||||||
#category : 'TinyBlog-Components',
|
#category : 'TinyBlog-Components',
|
||||||
#package : 'TinyBlog-Components'
|
#package : 'TinyBlog-Components'
|
||||||
@@ -48,12 +49,27 @@ TBPostsListComponent >> goToAdministrationView [
|
|||||||
self call: TBAdminComponent new
|
self call: TBAdminComponent new
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : 'as yet unclassified' }
|
||||||
|
TBPostsListComponent >> hasLoginError [
|
||||||
|
^ showLoginError ifNil: [ false ]
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : 'initialization' }
|
{ #category : 'initialization' }
|
||||||
TBPostsListComponent >> initialize [
|
TBPostsListComponent >> initialize [
|
||||||
super initialize.
|
super initialize.
|
||||||
postComponents := OrderedCollection new
|
postComponents := OrderedCollection new
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : 'as yet unclassified' }
|
||||||
|
TBPostsListComponent >> loginErrorMessage [
|
||||||
|
^ 'Incorrect login and/or password'
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'as yet unclassified' }
|
||||||
|
TBPostsListComponent >> loginErrorOccurred [
|
||||||
|
showLoginError := true
|
||||||
|
]
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
TBPostsListComponent >> postComponentFor: aPost [
|
TBPostsListComponent >> postComponentFor: aPost [
|
||||||
^ TBPostComponent new post: aPost
|
^ TBPostComponent new post: aPost
|
||||||
@@ -93,19 +109,32 @@ TBPostsListComponent >> renderContentOn: html [
|
|||||||
smallSize: 2;
|
smallSize: 2;
|
||||||
mediumSize: 4;
|
mediumSize: 4;
|
||||||
with: [ html render: self categoriesComponent ].
|
with: [ html render: self categoriesComponent ].
|
||||||
html column
|
self renderPostColumnOn: html ] ]
|
||||||
extraSmallSize: 12;
|
]
|
||||||
smallSize: 10;
|
|
||||||
mediumSize: 8;
|
{ #category : 'rendering' }
|
||||||
with: [
|
TBPostsListComponent >> renderLoginErrorMessageIfAnyOn: html [
|
||||||
self postComponents do: [ :p | html render: (self postComponentFor: p) ] ] ] ]
|
self hasLoginError ifTrue: [
|
||||||
|
showLoginError := false.
|
||||||
|
html alert
|
||||||
|
beDanger;
|
||||||
|
with: self loginErrorMessage ]
|
||||||
]
|
]
|
||||||
|
|
||||||
{ #category : 'rendering' }
|
{ #category : 'rendering' }
|
||||||
TBPostsListComponent >> renderPostColumnOn: html [
|
TBPostsListComponent >> renderPostColumnOn: html [
|
||||||
html column
|
html column
|
||||||
extraSmallSize: 12;
|
extraSmallSize: 12;
|
||||||
smallSize: 2;
|
smallSize: 10;
|
||||||
mediumSize: 4;
|
mediumSize: 8;
|
||||||
with: [ self basicRenderPostsOn: html ]
|
with: [
|
||||||
|
self renderLoginErrorMessageIfAnyOn: html.
|
||||||
|
self basicRenderPostsOn: html ]
|
||||||
|
]
|
||||||
|
|
||||||
|
{ #category : 'as yet unclassified' }
|
||||||
|
TBPostsListComponent >> tryConnectionWithLogin: login andPassword: password [
|
||||||
|
(login = 'admin' and: [ password = 'topsecret' ])
|
||||||
|
ifTrue: [ self goToAdministrationView ]
|
||||||
|
ifFalse: [ self loginErrorOccurred ]
|
||||||
]
|
]
|
||||||
|
Reference in New Issue
Block a user