Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit e1ee93eb
authored
Oct 13, 2018
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
väliaikacommit ,ei rkota mittään vahignossa
1 parent
b9a67499
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
141 additions
and
37 deletions
code/moya-angular/src/app/app-routing.module.ts
code/moya-angular/src/app/app.component.html
code/moya-angular/src/app/modules/login/login-button/login-button.component.css
code/moya-angular/src/app/modules/login/login-button/login-button.component.html
code/moya-angular/src/app/modules/login/login-button/login-button.component.spec.ts
code/moya-angular/src/app/modules/login/login-button/login-button.component.ts
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.html
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.ts
code/moya-angular/src/app/modules/login/login.module.ts
code/moya-angular/src/app/shared/models/user.model.ts
code/moya-angular/src/app/shared/services/session-service.service.ts
code/moya-angular/src/app/app-routing.module.ts
View file @
e1ee93e
...
@@ -4,7 +4,7 @@ import {FrontpageComponent} from './components/frontpage/frontpage.component';
...
@@ -4,7 +4,7 @@ import {FrontpageComponent} from './components/frontpage/frontpage.component';
import
{
LoginPageComponent
}
from
"./modules/login/login-page/login-page.component"
;
import
{
LoginPageComponent
}
from
"./modules/login/login-page/login-page.component"
;
const
APP_ROUTES
:
Routes
=
[
const
APP_ROUTES
:
Routes
=
[
{
path
:
'login'
,
component
:
LoginPageComponent
},
//
{ path: 'login', component: LoginPageComponent },
{
path
:
'viplist'
,
loadChildren
:
'app/modules/viplist/viplist.module#ViplistModule'
},
{
path
:
'viplist'
,
loadChildren
:
'app/modules/viplist/viplist.module#ViplistModule'
},
{
path
:
'old'
,
loadChildren
:
'app/modules/old-moya/old-moya.module#OldMoyaModule'
},
{
path
:
'old'
,
loadChildren
:
'app/modules/old-moya/old-moya.module#OldMoyaModule'
},
{
path
:
'index'
,
component
:
FrontpageComponent
},
{
path
:
'index'
,
component
:
FrontpageComponent
},
...
...
code/moya-angular/src/app/app.component.html
View file @
e1ee93e
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
<div
id=
"contentarea"
>
<div
id=
"contentarea"
>
<div
id=
"topbar"
>
<div
id=
"topbar"
>
<moya-top-menu></moya-top-menu>
<moya-top-menu></moya-top-menu>
<moya-login-
dialog></moya-login-dialog
>
<moya-login-
button></moya-login-button
>
<moya-locale></moya-locale>
<moya-locale></moya-locale>
</div>
</div>
<div
id=
"content"
>
<div
id=
"content"
>
...
...
code/moya-angular/src/app/modules/login/login-button/login-button.component.css
0 → 100644
View file @
e1ee93e
File mode changed
code/moya-angular/src/app/modules/login/login-button/login-button.component.html
0 → 100644
View file @
e1ee93e
<button
*
ngIf=
"!loggedIn"
mat-raised-button
(
click
)="
openLoginDialog
()"
tabindex=
"8"
>
{{ "login.login" | translate}}
</button>
<button
tabindex=
"8"
*
ngIf=
"loggedIn"
mat-button
[
matMenuTriggerFor
]="
logoutMenu
"
>
{{currentUser.firstname}} ({{currentUser.nick}}) {{currentUser.lastname}}
</button>
<mat-menu
#
logoutMenu=
"matMenu"
>
<button
mat-menu-item
(
click
)="
logout
()"
>
{{ "login.logout" | translate}}
</button>
</mat-menu>
code/moya-angular/src/app/modules/login/login-button/login-button.component.spec.ts
0 → 100644
View file @
e1ee93e
import
{
async
,
ComponentFixture
,
TestBed
}
from
'@angular/core/testing'
;
import
{
LoginButtonComponent
}
from
'./login-button.component'
;
describe
(
'LoginButtonComponent'
,
()
=>
{
let
component
:
LoginButtonComponent
;
let
fixture
:
ComponentFixture
<
LoginButtonComponent
>
;
beforeEach
(
async
(()
=>
{
TestBed
.
configureTestingModule
({
declarations
:
[
LoginButtonComponent
]
})
.
compileComponents
();
}));
beforeEach
(()
=>
{
fixture
=
TestBed
.
createComponent
(
LoginButtonComponent
);
component
=
fixture
.
componentInstance
;
fixture
.
detectChanges
();
});
it
(
'should create'
,
()
=>
{
expect
(
component
).
toBeTruthy
();
});
});
code/moya-angular/src/app/modules/login/login-button/login-button.component.ts
0 → 100644
View file @
e1ee93e
import
{
Component
,
OnInit
}
from
'@angular/core'
;
import
{
MatDialog
,
MatDialogConfig
}
from
"@angular/material"
;
import
{
LoginComponent
}
from
"../login-component/login.component"
;
import
{
Router
}
from
"@angular/router"
;
import
{
SessionServiceService
}
from
"../../../shared/services/session-service.service"
;
import
{
EventUser
}
from
"../../../shared/models/event-user.model"
;
import
{
User
}
from
"../../../shared/models/user.model"
;
@
Component
({
selector
:
'moya-login-button'
,
templateUrl
:
'./login-button.component.html'
,
styleUrls
:
[
'./login-button.component.css'
]
})
export
class
LoginButtonComponent
implements
OnInit
{
loggedIn
=
false
;
currentUser
:
User
=
null
;
constructor
(
private
router
:
Router
,
private
dialog
:
MatDialog
,
private
sessionService
:
SessionServiceService
)
{
this
.
sessionService
.
getCurrentUser
().
subscribe
((
user
:
User
)
=>
{
this
.
loggedIn
=
!
user
.
isAnonymous
();
this
.
currentUser
=
user
;
});
}
logout
()
{
this
.
sessionService
.
logout
();
}
ngOnInit
()
{
}
openLoginDialog
():
void
{
let
conf
=
new
MatDialogConfig
();
conf
.
autoFocus
=
true
;
/*conf.height = "800px";
conf.width = "500px";*/
let
dialogRef
=
this
.
dialog
.
open
(
LoginComponent
,
conf
);
dialogRef
.
componentInstance
.
loginEvent
.
subscribe
((
success
)
=>
{
if
(
success
)
{
dialogRef
.
close
();
}
else
{
dialogRef
.
close
();
this
.
router
.
navigateByUrl
(
"/login"
);
}
});
}
}
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.html
View file @
e1ee93e
ei toimi
<button
mat-raised-button
(
click
)="
openLoginDialog
()"
tabindex=
"8"
>
{{ "login.login" | translate}}
</button>
code/moya-angular/src/app/modules/login/login-dialog/login-dialog.component.ts
View file @
e1ee93e
...
@@ -15,24 +15,6 @@ export class LoginDialogComponent implements OnInit {
...
@@ -15,24 +15,6 @@ export class LoginDialogComponent implements OnInit {
ngOnInit
()
{
ngOnInit
()
{
}
}
openLoginDialog
():
void
{
let
conf
=
new
MatDialogConfig
();
conf
.
autoFocus
=
true
;
/*conf.height = "800px";
conf.width = "500px";*/
let
dialogRef
=
this
.
dialog
.
open
(
LoginComponent
,
conf
);
dialogRef
.
componentInstance
.
loginEvent
.
subscribe
((
success
)
=>
{
if
(
success
)
{
dialogRef
.
close
();
}
else
{
dialogRef
.
close
();
this
.
router
.
navigateByUrl
(
"/login"
);
}
});
}
}
}
code/moya-angular/src/app/modules/login/login.module.ts
View file @
e1ee93e
import
{
NgModule
}
from
'@angular/core'
;
import
{
NgModule
}
from
'@angular/core'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
CommonModule
}
from
'@angular/common'
;
import
{
MatButtonModule
,
MatCardModule
,
MatDialogModule
,
MatFormFieldModule
,
MatInputModule
,
MatToolbarModule
}
from
'@angular/material'
;
import
{
MatButtonModule
,
MatCardModule
,
MatDialogModule
,
MatFormFieldModule
,
MatInputModule
,
MatMenuModule
,
MatToolbarModule
}
from
'@angular/material'
;
import
{
TranslateModule
}
from
'@ngx-translate/core'
;
import
{
TranslateModule
}
from
'@ngx-translate/core'
;
import
{
BrowserAnimationsModule
}
from
'@angular/platform-browser/animations'
;
import
{
BrowserAnimationsModule
}
from
'@angular/platform-browser/animations'
;
import
{
FormsModule
}
from
'@angular/forms'
;
import
{
FormsModule
}
from
'@angular/forms'
;
import
{
LoginPageComponent
}
from
'./login-page/login-page.component'
;
import
{
LoginPageComponent
}
from
'./login-page/login-page.component'
;
import
{
LoginComponent
}
from
'./login-component/login.component'
;
import
{
LoginComponent
}
from
'./login-component/login.component'
;
import
{
LoginDialogComponent
}
from
'./login-dialog/login-dialog.component'
;
import
{
LoginDialogComponent
}
from
'./login-dialog/login-dialog.component'
;
import
{
LoginButtonComponent
}
from
'./login-button/login-button.component'
;
@
NgModule
({
@
NgModule
({
imports
:
[
imports
:
[
...
@@ -21,13 +30,14 @@ import { LoginDialogComponent } from './login-dialog/login-dialog.component';
...
@@ -21,13 +30,14 @@ import { LoginDialogComponent } from './login-dialog/login-dialog.component';
MatCardModule
,
MatCardModule
,
MatDialogModule
,
MatDialogModule
,
MatToolbarModule
,
MatToolbarModule
,
MatMenuModule
],
],
entryComponents
:
[
LoginComponent
],
entryComponents
:
[
LoginComponent
],
declarations
:
[
LoginComponent
,
LoginPageComponent
,
LoginDialogComponent
],
declarations
:
[
LoginComponent
,
LoginPageComponent
,
LoginDialogComponent
,
LoginButtonComponent
],
exports
:
[
exports
:
[
LoginComponent
LoginComponent
,
LoginButtonComponent
]
]
})
})
...
...
code/moya-angular/src/app/shared/models/user.model.ts
View file @
e1ee93e
...
@@ -16,6 +16,8 @@ export class User {
...
@@ -16,6 +16,8 @@ export class User {
static
fragments
=
gql
`
static
fragments
=
gql
`
fragment userPrimitives on User {
fragment userPrimitives on User {
address
address
...
@@ -55,6 +57,17 @@ export class User {
...
@@ -55,6 +57,17 @@ export class User {
zip
:
string
;
zip
:
string
;
town
:
string
;
town
:
string
;
public
isAnonymous
():
boolean
{
return
!
this
.
login
||
this
.
login
===
"anonymous"
;
}
public
static
NewUser
(
user
)
{
if
(
user
===
null
)
return
new
User
();
return
Object
.
assign
(
new
User
(),
user
);
}
constructor
()
{
}
}
}
code/moya-angular/src/app/shared/services/session-service.service.ts
View file @
e1ee93e
...
@@ -7,6 +7,8 @@ import {MOYA_BASE_URL, MOYA_REST_URL} from '../config/moya.config';
...
@@ -7,6 +7,8 @@ import {MOYA_BASE_URL, MOYA_REST_URL} from '../config/moya.config';
import
{
map
,
share
}
from
'rxjs/operators'
;
import
{
map
,
share
}
from
'rxjs/operators'
;
import
{
HttpClient
,
HttpHeaders
,
HttpParams
}
from
'@angular/common/http'
;
import
{
HttpClient
,
HttpHeaders
,
HttpParams
}
from
'@angular/common/http'
;
import
{
EventUser
}
from
"../models/event-user.model"
;
import
{
EventUser
}
from
"../models/event-user.model"
;
import
{
User
}
from
"../models/user.model"
;
import
{
Router
}
from
"@angular/router"
;
...
@@ -44,9 +46,9 @@ export class SessionServiceService {
...
@@ -44,9 +46,9 @@ export class SessionServiceService {
private
permissionsObservable
:
Observable
<
Permissions
>
;
private
permissionsObservable
:
Observable
<
Permissions
>
;
private
permissionsApollo
:
QueryRef
<
ApiPermissionRoot
>
;
private
permissionsApollo
:
QueryRef
<
ApiPermissionRoot
>
;
private
currentuserSubject
:
BehaviorSubject
<
Event
User
>
;
private
currentuserSubject
:
BehaviorSubject
<
User
>
;
constructor
(
private
apollo
:
Apollo
,
private
http
:
HttpClient
)
{
constructor
(
private
apollo
:
Apollo
,
private
http
:
HttpClient
,
private
router
:
Router
)
{
// Permissions apollo call.
// Permissions apollo call.
...
@@ -65,7 +67,7 @@ export class SessionServiceService {
...
@@ -65,7 +67,7 @@ export class SessionServiceService {
// make subject to share the current user.
// make subject to share the current user.
// This way we can later on update it to everyone who is listening this beautiful observable
// This way we can later on update it to everyone who is listening this beautiful observable
this
.
currentuserSubject
=
new
BehaviorSubject
(
null
);
this
.
currentuserSubject
=
new
BehaviorSubject
<
User
>
(
null
);
this
.
updateCurrentUser
();
this
.
updateCurrentUser
();
...
@@ -82,8 +84,8 @@ export class SessionServiceService {
...
@@ -82,8 +84,8 @@ export class SessionServiceService {
*
*
* If there is any change of user status, new user is automatically pushed into this observable.
* If there is any change of user status, new user is automatically pushed into this observable.
*/
*/
public
getCurrentUser
():
Observable
<
Event
User
>
{
public
getCurrentUser
():
Observable
<
User
>
{
return
this
.
currentuserSubject
;
return
this
.
currentuserSubject
.
pipe
(
map
(
user
=>
User
.
NewUser
(
user
)))
;
}
}
/**
/**
...
@@ -92,12 +94,10 @@ export class SessionServiceService {
...
@@ -92,12 +94,10 @@ export class SessionServiceService {
* This will push currently logged in user into currentUser -observable.
* This will push currently logged in user into currentUser -observable.
*/
*/
public
updateCurrentUser
()
{
public
updateCurrentUser
()
{
this
.
http
.
get
<
Event
User
>
(
MOYA_REST_URL
+
"/v2/user/current"
).
subscribe
(
this
.
http
.
get
<
User
>
(
MOYA_REST_URL
+
"/v2/user/current"
).
subscribe
(
(
currentUser
)
=>
{
(
currentUser
)
=>
{
this
.
currentuserSubject
.
next
(
currentUser
);
this
.
currentuserSubject
.
next
(
currentUser
);
});
});
}
}
...
@@ -127,9 +127,27 @@ export class SessionServiceService {
...
@@ -127,9 +127,27 @@ export class SessionServiceService {
this
.
updateCurrentUser
();
this
.
updateCurrentUser
();
});
});
return
apolloObservable
;
}
public
logout
()
{
return
apolloObservable
;
// Do login with unexiting user and password, this does also logout
let
params
=
new
HttpParams
();
params
=
params
.
set
(
'username'
,
"anonymous"
);
params
=
params
.
set
(
'password'
,
"notValidPassword"
);
const
apolloObservable
=
this
.
http
.
post
(
MOYA_REST_URL
+
'/user/auth'
,
params
,
{
headers
:
new
HttpHeaders
()
.
set
(
'Content-Type'
,
'application/x-www-form-urlencoded'
)
}).
subscribe
(
x
=>
x
,
x
=>
x
,
()
=>
{
this
.
permissionsApollo
.
refetch
();
this
.
updateCurrentUser
();
this
.
router
.
navigateByUrl
(
"/"
);
});
}
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment