TAK-57 edit tab
This commit is contained in:
parent
8136196b60
commit
0f64f92b0d
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.idea
|
||||||
|
app/.Rhistory
|
||||||
|
backend/target/
|
||||||
|
db.sqlite
|
||||||
|
backend/.idea/
|
15
app/app.R
15
app/app.R
@ -18,13 +18,14 @@ ui <- fluidPage(
|
|||||||
tags$head(
|
tags$head(
|
||||||
tags$script(src="js.cookie.js"),
|
tags$script(src="js.cookie.js"),
|
||||||
|
|
||||||
tags$script('var cookie = Cookies.get(\'token\');
|
|
||||||
$(document).on("shiny:sessioninitialized",function(event){
|
tags$script('var token = sessionStorage.getItem(\'token\');
|
||||||
Shiny.onInputChange("token", cookie);});'),
|
$(document).on("shiny:sessioninitialized",function(event){
|
||||||
tags$script('Shiny.addCustomMessageHandler("tokenHandler",
|
Shiny.onInputChange("token", token);});'),
|
||||||
|
tags$script('Shiny.addCustomMessageHandler("tokenHandler",
|
||||||
function(token) {
|
function(token) {
|
||||||
var cookie = Cookies.set(\'token\', token, { expires: 7 });
|
sessionStorage.setItem(\'token\', token);
|
||||||
Shiny.onInputChange("token", cookie);
|
Shiny.onInputChange("token", token);
|
||||||
|
|
||||||
}
|
}
|
||||||
);')
|
);')
|
||||||
@ -114,7 +115,7 @@ shinyjs::onclick(id="tab1",expr = {
|
|||||||
shinyjs::removeCssClass(id="tab1",class = "clicked")
|
shinyjs::removeCssClass(id="tab1",class = "clicked")
|
||||||
shinyjs::removeCssClass(id="tab4",class = "clicked")
|
shinyjs::removeCssClass(id="tab4",class = "clicked")
|
||||||
}else{
|
}else{
|
||||||
shinyjs::runjs( 'Cookies.remove(\'token\');
|
shinyjs::runjs( 'sessionStorage.removeItem(\'token\');
|
||||||
|
|
||||||
Shiny.onInputChange("token", null);
|
Shiny.onInputChange("token", null);
|
||||||
window.location.replace(\'/#!/login\');')
|
window.location.replace(\'/#!/login\');')
|
||||||
|
@ -12,18 +12,11 @@ homeUI <- function(id) {
|
|||||||
@import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700');
|
@import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700');
|
||||||
@import url('//fonts.googleapis.com/css2?family=Fjalla+One');
|
@import url('//fonts.googleapis.com/css2?family=Fjalla+One');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"))),
|
"))),
|
||||||
|
|
||||||
theme = "style.css",
|
theme = "style.css",
|
||||||
|
|
||||||
|
|
||||||
# App title ----
|
|
||||||
# App title ----
|
|
||||||
|
|
||||||
# h4("Aplikacja wspomagajaca diagnozowanie i monitorowanie stanu zdrowia", align = "center"),
|
|
||||||
|
|
||||||
fluidRow(column(12,
|
fluidRow(column(12,
|
||||||
h1("TakeCareApp"))%>% tagAppendAttributes(id = 'column-title')
|
h1("TakeCareApp"))%>% tagAppendAttributes(id = 'column-title')
|
||||||
|
@ -13,10 +13,11 @@ loginUI <- function(id) {
|
|||||||
useShinyjs(),
|
useShinyjs(),
|
||||||
tags$head(
|
tags$head(
|
||||||
tags$script(src="js.cookie.js"),
|
tags$script(src="js.cookie.js"),
|
||||||
tags$script('Shiny.addCustomMessageHandler("tokenHandlerAfterLogin",
|
|
||||||
|
tags$script('Shiny.addCustomMessageHandler("tokenHandlerAfterLogin",
|
||||||
function(token) {
|
function(token) {
|
||||||
var cookie = Cookies.set(\'token\', token, { expires: 7 });
|
sessionStorage.setItem(\'token\', token);
|
||||||
Shiny.onInputChange("token", cookie);
|
Shiny.onInputChange("token", token);
|
||||||
|
|
||||||
window.location.replace(\'/#!/profil\');
|
window.location.replace(\'/#!/profil\');
|
||||||
}
|
}
|
||||||
@ -66,10 +67,9 @@ loginServer <- function(input, output,session) {
|
|||||||
if(r$status_code==200){
|
if(r$status_code==200){
|
||||||
|
|
||||||
response<-(content(r))
|
response<-(content(r))
|
||||||
|
|
||||||
session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token)
|
session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TRUE
|
TRUE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ loginServer <- function(input, output,session) {
|
|||||||
observe({
|
observe({
|
||||||
if(((session$clientData)$url_hash=="#!/login") & (!is.null(input$token) & length(input$token)>0 )){
|
if(((session$clientData)$url_hash=="#!/login") & (!is.null(input$token) & length(input$token)>0 )){
|
||||||
|
|
||||||
print("dziala")
|
|
||||||
shinyjs::runjs('window.location.replace(\'/#!/home\');')
|
shinyjs::runjs('window.location.replace(\'/#!/home\');')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -11,14 +11,16 @@ profilUI <- function(id) {
|
|||||||
tags$head(
|
tags$head(
|
||||||
tags$script(src="js.cookie.js"),
|
tags$script(src="js.cookie.js"),
|
||||||
|
|
||||||
|
|
||||||
tags$style(HTML("
|
tags$style(HTML("
|
||||||
@import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700');
|
@import url('//fonts.googleapis.com/css?family=Lobster|Cabin:400,700');
|
||||||
@import url('//fonts.googleapis.com/css2?family=Fjalla+One');
|
@import url('//fonts.googleapis.com/css2?family=Fjalla+One');
|
||||||
|
|
||||||
|
")),
|
||||||
|
tags$link(rel = "stylesheet", type = "text/css", href = "profile.css")
|
||||||
|
),
|
||||||
|
|
||||||
"))),
|
# theme = "style.css",
|
||||||
|
|
||||||
theme = "style.css",
|
|
||||||
|
|
||||||
|
|
||||||
# App title ----
|
# App title ----
|
||||||
@ -41,6 +43,47 @@ profilServer <- function(input, output,session) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
getEditStatus <- eventReactive(input$editSubmit, {
|
||||||
|
editedPersonalData<-data.frame(name<-input$editName,
|
||||||
|
surname<-input$editSurname,
|
||||||
|
mail<-input$editMail,
|
||||||
|
datebirth<-input$editAge,
|
||||||
|
gender<-input$editGender)
|
||||||
|
|
||||||
|
reg<-c(grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,15}$",editedPersonalData$name),
|
||||||
|
grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,20}$",editedPersonalData$surname),
|
||||||
|
grepl("^[a-z]+[0-9]*@([a-z]{2,10}\\.)+[a-z]{2,5}$",editedPersonalData$mail))
|
||||||
|
if(all(reg)){
|
||||||
|
# status$status = register(result)
|
||||||
|
|
||||||
|
# status$first = FALSE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
to_send = list(name = editedPersonalData$name,
|
||||||
|
surname = editedPersonalData$surname,
|
||||||
|
email = editedPersonalData$mail,
|
||||||
|
datebirth = editedPersonalData$datebirth,
|
||||||
|
gender = editedPersonalData$gender)
|
||||||
|
|
||||||
|
r<-httr::PUT("http://localhost:8080/api/profile",add_headers(Authorization=paste("Bearer",input$token,sep=" ")),body=to_send,encode = 'json')
|
||||||
|
|
||||||
|
if (r$status_code==200){
|
||||||
|
TRUE
|
||||||
|
}else{
|
||||||
|
FALSE
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
|
||||||
|
FALSE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
observe({
|
observe({
|
||||||
if(( (session$clientData)$url_hash=="#!/profil")){
|
if(( (session$clientData)$url_hash=="#!/profil")){
|
||||||
@ -51,11 +94,60 @@ profilServer <- function(input, output,session) {
|
|||||||
|
|
||||||
shinyjs::runjs('window.location.replace(\'/#!/home\');')
|
shinyjs::runjs('window.location.replace(\'/#!/home\');')
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
output$profileData<-renderUI({
|
||||||
|
|
||||||
|
|
||||||
|
r<-httr::GET("http://localhost:8080/api/profile",add_headers(Authorization=paste("Bearer",input$token,sep=" ")))
|
||||||
|
|
||||||
|
if(r$status_code==200){
|
||||||
|
|
||||||
|
response<-(content(r))
|
||||||
|
|
||||||
|
session$sendCustomMessage(type='tokenHandlerAfterLogin', response$token)
|
||||||
|
|
||||||
|
|
||||||
|
fluidRow(column(12,
|
||||||
|
wellPanel(
|
||||||
|
textInput("editName", label = strong("Imie"),value=response$profil$name),
|
||||||
|
uiOutput("editName"),
|
||||||
|
textInput("editSurname", label = strong("Nazwisko"),value=response$profil$surname),
|
||||||
|
uiOutput("editSurname"),
|
||||||
|
textInput("editMail", label = strong("Adres email"),value=response$profil$email),
|
||||||
|
uiOutput("editMail"),
|
||||||
|
dateInput("editAge", label = strong("Data urodzenia") ,value=response$profil$datebirth),
|
||||||
|
|
||||||
|
selectInput("editGender", label = strong("Plec"),
|
||||||
|
choices = list("Żenska" = 0, "Meska" = 1),
|
||||||
|
selected = as.numeric(response$profil$gender)),
|
||||||
|
|
||||||
|
),
|
||||||
|
|
||||||
|
actionButton("editSubmit","Zapisz"),
|
||||||
|
uiOutput("btnEditProfile",style="color:red;")
|
||||||
|
|
||||||
|
))
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
output$btnEditProfile<-renderUI({
|
||||||
|
|
||||||
|
if (getEditStatus()==TRUE){
|
||||||
|
p("OK",style="color:green;text-align:center;")
|
||||||
|
}else{
|
||||||
|
p("Uzytkownik istnieje lub wprowadzono bledne dane",style="color:red;text-align:center;")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
output$afterLogin<-renderUI({
|
output$afterLogin<-renderUI({
|
||||||
@ -70,7 +162,8 @@ profilServer <- function(input, output,session) {
|
|||||||
)%>% tagAppendAttributes(id = 'column-panel'),
|
)%>% tagAppendAttributes(id = 'column-panel'),
|
||||||
column(9,
|
column(9,
|
||||||
tabsetPanel(type = "tabs",
|
tabsetPanel(type = "tabs",
|
||||||
tabPanel("Zakładka 1", tags$div(plotlyOutput("plot1",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
tabPanel("Dane profilowe", tags$div(uiOutput("profileData")
|
||||||
|
)%>% tagAppendAttributes(class = 'content-wrapper')),
|
||||||
tabPanel("Zakładka 2", tags$div(plotlyOutput("plot2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
tabPanel("Zakładka 2", tags$div(plotlyOutput("plot2",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
||||||
tabPanel("Zakładka 3", tags$div(plotlyOutput("plot3",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
tabPanel("Zakładka 3", tags$div(plotlyOutput("plot3",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
||||||
tabPanel("Zakładka 4", tags$div(plotlyOutput("plot4",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
tabPanel("Zakładka 4", tags$div(plotlyOutput("plot4",height = "auto"))%>% tagAppendAttributes(class = 'content-wrapper')),
|
||||||
@ -145,6 +238,53 @@ profilServer <- function(input, output,session) {
|
|||||||
output$table1 <- DT::renderDataTable(iris,options = list(scrollX = TRUE,language=pl))
|
output$table1 <- DT::renderDataTable(iris,options = list(scrollX = TRUE,language=pl))
|
||||||
|
|
||||||
|
|
||||||
|
output$btnResponse<-renderUI({
|
||||||
|
|
||||||
|
if (getStatus()==TRUE){
|
||||||
|
p("OK",style="color:white;text-align:center;")
|
||||||
|
}else{
|
||||||
|
p("Uzytkownik istnieje lub wprowadzono bledne dane",style="color:yellow;text-align:center;")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
output$editName<-renderUI({
|
||||||
|
s<-toString(input$editName)
|
||||||
|
|
||||||
|
if (s=="" | grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,15}$",s)==TRUE){
|
||||||
|
return()
|
||||||
|
}else{
|
||||||
|
p("Bład: Imie powinno zaczynac sie od wielkiej litery, zawierac jedynie litery i miec dlugosc od 3 do 15 znaków",style="color:yellow")
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
output$editSurname<-renderUI({
|
||||||
|
s<-toString(input$editSurname)
|
||||||
|
|
||||||
|
if (s=="" | grepl("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,20}$",s)==TRUE){
|
||||||
|
return()
|
||||||
|
}else{
|
||||||
|
p("Bład: Nazwisko powinno zaczynac sie od wielkiej litery, zawierac jedynie litery i miec dlugosc od 3 do 15 znaków",style="color:yellow")
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
output$editMail<-renderUI({
|
||||||
|
s<-toString(input$editMail)
|
||||||
|
|
||||||
|
if (s=="" | grepl("^[a-z]+[0-9]*@([a-z]{2,10}\\.)+[a-z]{2,5}$",s)==TRUE){
|
||||||
|
return()
|
||||||
|
}else{
|
||||||
|
p("Bład: Mail powinien miec budowe adres@nazwa.domena",style="color:yellow")
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ registerServer <- function(input, output,session) {
|
|||||||
observe({
|
observe({
|
||||||
if(((session$clientData)$url_hash=="#!/register") & (!is.null(input$token) & length(input$token)>0 )){
|
if(((session$clientData)$url_hash=="#!/register") & (!is.null(input$token) & length(input$token)>0 )){
|
||||||
|
|
||||||
print("dziala")
|
|
||||||
shinyjs::runjs('window.location.replace(\'/#!/home\');')
|
shinyjs::runjs('window.location.replace(\'/#!/home\');')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -67,7 +67,7 @@ registerServer <- function(input, output,session) {
|
|||||||
grepl("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]+[0-9\\-\\_]*){5,20}$",result$username),
|
grepl("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]+[0-9\\-\\_]*){5,20}$",result$username),
|
||||||
grepl("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{5,}[0-9]{5,}[a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż0-9]*)+$",result$password))
|
grepl("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{5,}[0-9]{5,}[a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż0-9]*)+$",result$password))
|
||||||
if(all(reg) & all(result$permission==c(1,2))){
|
if(all(reg) & all(result$permission==c(1,2))){
|
||||||
# status$status = register(result)
|
|
||||||
|
|
||||||
status$first = FALSE
|
status$first = FALSE
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ registerServer <- function(input, output,session) {
|
|||||||
password= result$password,
|
password= result$password,
|
||||||
roleDTO= "IND")
|
roleDTO= "IND")
|
||||||
r<-httr::POST("http://localhost:8080/api/register",body=to_send,encode = 'json')
|
r<-httr::POST("http://localhost:8080/api/register",body=to_send,encode = 'json')
|
||||||
print(content(r, "text"))
|
|
||||||
if (r$status_code==200){
|
if (r$status_code==200){
|
||||||
status$status = TRUE
|
status$status = TRUE
|
||||||
}else{
|
}else{
|
||||||
|
17
app/www/profile.css
Normal file
17
app/www/profile.css
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#profileData{
|
||||||
|
display:flex;
|
||||||
|
justify-content:center;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#profileData > .row,#profileData > .row > .well{
|
||||||
|
width:100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#profileData > .row .well{
|
||||||
|
#display:flex;
|
||||||
|
color:white;
|
||||||
|
background-color:#00A896;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -281,7 +281,7 @@ font-family:Fjalla One;
|
|||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
#submit,#loginBtn{
|
#submit,#loginBtn,#editSubmit{
|
||||||
margin-top:20px;
|
margin-top:20px;
|
||||||
align-self:center;
|
align-self:center;
|
||||||
min-width:25%;
|
min-width:25%;
|
||||||
|
@ -12,6 +12,9 @@
|
|||||||
<module name="backend" />
|
<module name="backend" />
|
||||||
</profile>
|
</profile>
|
||||||
</annotationProcessing>
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="backend" target="1.8" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
</component>
|
</component>
|
||||||
<component name="JavacSettings">
|
<component name="JavacSettings">
|
||||||
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
|
||||||
|
@ -2,11 +2,9 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="2f11f4d5-1593-4266-846c-71ac633cf58a" name="Default" comment="">
|
<list default="true" id="2f11f4d5-1593-4266-846c-71ac633cf58a" name="Default" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/../app/.Rhistory" beforeDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../app/app.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/app.R" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/../app/app.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/app.R" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/../app/login_module.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/login_module.R" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/../app/login_module.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/login_module.R" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/../app/profil_module.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/profil_module.R" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/../app/profil_module.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/profil_module.R" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/../app/register_module.R" beforeDir="false" afterPath="$PROJECT_DIR$/../app/register_module.R" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/../app/www/style.css" beforeDir="false" afterPath="$PROJECT_DIR$/../app/www/style.css" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/../app/www/style.css" beforeDir="false" afterPath="$PROJECT_DIR$/../app/www/style.css" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -183,42 +181,43 @@
|
|||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state x="445" y="208" key="#com.intellij.ide.util.MemberChooser/0.0.1280.984@0.0.1280.984" timestamp="1608284675573" />
|
<state x="445" y="208" key="#com.intellij.ide.util.MemberChooser/0.0.1280.984@0.0.1280.984" timestamp="1608284675573" />
|
||||||
<state x="618" y="301" key="#com.intellij.ide.util.projectWizard.JdkChooserPanel.MyDialog" timestamp="1606136940050">
|
<state x="515" y="359" key="#com.intellij.ide.util.projectWizard.JdkChooserPanel.MyDialog" timestamp="1608416401063">
|
||||||
<screen x="0" y="0" width="1536" height="824" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
|
<state x="515" y="359" key="#com.intellij.ide.util.projectWizard.JdkChooserPanel.MyDialog/0.0.1280.984@0.0.1280.984" timestamp="1608416401063" />
|
||||||
<state x="618" y="301" key="#com.intellij.ide.util.projectWizard.JdkChooserPanel.MyDialog/0.0.1536.824@0.0.1536.824" timestamp="1606136940050" />
|
<state x="618" y="301" key="#com.intellij.ide.util.projectWizard.JdkChooserPanel.MyDialog/0.0.1536.824@0.0.1536.824" timestamp="1606136940050" />
|
||||||
<state x="370" y="239" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1608284351336">
|
<state x="370" y="239" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog" timestamp="1608284351336">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state x="370" y="239" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1280.984@0.0.1280.984" timestamp="1608284351336" />
|
<state x="370" y="239" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1280.984@0.0.1280.984" timestamp="1608284351336" />
|
||||||
<state x="420" y="247" key="FileChooserDialogImpl" timestamp="1608392985023">
|
<state x="420" y="247" key="FileChooserDialogImpl" timestamp="1608416486787">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state x="420" y="247" key="FileChooserDialogImpl/0.0.1280.984@0.0.1280.984" timestamp="1608392985023" />
|
<state x="420" y="247" key="FileChooserDialogImpl/0.0.1280.984@0.0.1280.984" timestamp="1608416486787" />
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.bottom" timestamp="1608415904493">
|
<state width="1237" height="144" key="GridCell.Tab.0.bottom" timestamp="1608474806471">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.bottom/0.0.1280.984@0.0.1280.984" timestamp="1608415904493" />
|
<state width="1237" height="144" key="GridCell.Tab.0.bottom/0.0.1280.984@0.0.1280.984" timestamp="1608474806471" />
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.center" timestamp="1608415904493">
|
<state width="1237" height="144" key="GridCell.Tab.0.center" timestamp="1608474806471">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.center/0.0.1280.984@0.0.1280.984" timestamp="1608415904493" />
|
<state width="1237" height="144" key="GridCell.Tab.0.center/0.0.1280.984@0.0.1280.984" timestamp="1608474806471" />
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.left" timestamp="1608415904492">
|
<state width="1237" height="144" key="GridCell.Tab.0.left" timestamp="1608474806471">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.left/0.0.1280.984@0.0.1280.984" timestamp="1608415904492" />
|
<state width="1237" height="144" key="GridCell.Tab.0.left/0.0.1280.984@0.0.1280.984" timestamp="1608474806471" />
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.right" timestamp="1608415904493">
|
<state width="1237" height="144" key="GridCell.Tab.0.right" timestamp="1608474806471">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state width="1237" height="260" key="GridCell.Tab.0.right/0.0.1280.984@0.0.1280.984" timestamp="1608415904493" />
|
<state width="1237" height="144" key="GridCell.Tab.0.right/0.0.1280.984@0.0.1280.984" timestamp="1608474806471" />
|
||||||
<state x="231" y="66" key="SettingsEditor" timestamp="1608415647081">
|
<state x="231" y="66" key="SettingsEditor" timestamp="1608416474275">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state x="231" y="66" key="SettingsEditor/0.0.1280.984@0.0.1280.984" timestamp="1608415647081" />
|
<state x="231" y="66" key="SettingsEditor/0.0.1280.984@0.0.1280.984" timestamp="1608416474275" />
|
||||||
<state x="277" y="55" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1606136640031" />
|
<state x="277" y="55" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1606136640031" />
|
||||||
<state x="336" y="316" key="com.intellij.ide.util.TipDialog" timestamp="1608387076100">
|
<state x="336" y="316" key="com.intellij.ide.util.TipDialog" timestamp="1608473085786">
|
||||||
<screen x="0" y="0" width="1280" height="984" />
|
<screen x="0" y="0" width="1280" height="984" />
|
||||||
</state>
|
</state>
|
||||||
<state x="336" y="316" key="com.intellij.ide.util.TipDialog/0.0.1280.984@0.0.1280.984" timestamp="1608387076100" />
|
<state x="336" y="316" key="com.intellij.ide.util.TipDialog/0.0.1280.984@0.0.1280.984" timestamp="1608473085786" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -79,4 +79,5 @@ public class UserDTO implements Serializable {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public class TokenHelper implements Serializable {
|
|||||||
//Generate Token with userID,role,name
|
//Generate Token with userID,role,name
|
||||||
|
|
||||||
public String generateToken(User user) {
|
public String generateToken(User user) {
|
||||||
Claims claims = Jwts.claims().setSubject(user.getName());
|
Claims claims = Jwts.claims().setSubject(user.getLogin());
|
||||||
claims.put("userId",user.getId());
|
claims.put("userId",user.getId());
|
||||||
claims.put("role",user.getRole().getName());
|
claims.put("role",user.getRole().getName());
|
||||||
|
|
||||||
|
@ -49,10 +49,6 @@ public class AuthenticationController {
|
|||||||
String token=null;
|
String token=null;
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String,Object> map = new HashMap<>();
|
||||||
|
|
||||||
System.out.println(loginForm.getLogin());
|
|
||||||
System.out.println(loginForm.getPassword());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Optional<User> userFromDatabase = this.userService.getUsersByLogin(loginForm.getLogin());
|
Optional<User> userFromDatabase = this.userService.getUsersByLogin(loginForm.getLogin());
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import project.DTO.UserDTO;
|
import project.DTO.UserDTO;
|
||||||
|
import project.config.TokenHelper;
|
||||||
import project.model.*;
|
import project.model.*;
|
||||||
import project.services.GeneratorDTO;
|
import project.services.GeneratorDTO;
|
||||||
import project.services.RoleService;
|
import project.services.RoleService;
|
||||||
@ -38,7 +39,8 @@ public class UserController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private GeneratorDTO generatorDTO;
|
private GeneratorDTO generatorDTO;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TokenHelper tokenHelper;
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -57,20 +59,10 @@ public class UserController {
|
|||||||
Object token = request.getAttribute("token");
|
Object token = request.getAttribute("token");
|
||||||
map.put("token",token);
|
map.put("token",token);
|
||||||
|
|
||||||
System.out.println("REGISTER IN");
|
|
||||||
System.out.println(userDTO.getLogin());
|
|
||||||
System.out.println(userDTO.getPassword());
|
|
||||||
|
|
||||||
Optional<User> users = this.userService.getUsersByLogin(userDTO.getLogin());
|
Optional<User> users = this.userService.getUsersByLogin(userDTO.getLogin());
|
||||||
|
|
||||||
|
|
||||||
Pattern pName =Pattern.compile("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,15}$");
|
|
||||||
Pattern pSurname =Pattern.compile("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,20}$");
|
|
||||||
Pattern pEmail =Pattern.compile("^[a-z]+[0-9]*@([a-z]{2,10}\\.)+[a-z]{2,5}$");
|
|
||||||
Pattern pLogin =Pattern.compile("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]+[0-9\\-\\_]*){5,20}$");
|
|
||||||
Pattern pPassword =Pattern.compile("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{5,}[0-9]{5,}[a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż0-9]*)+$");
|
|
||||||
|
|
||||||
|
|
||||||
if(users.isPresent()){
|
if(users.isPresent()){
|
||||||
|
|
||||||
map.put("message","Wprowadzony użytkownik już istnieje");
|
map.put("message","Wprowadzony użytkownik już istnieje");
|
||||||
@ -79,15 +71,8 @@ public class UserController {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(!pName.matcher(userDTO.getName()).matches() | !pSurname.matcher(userDTO.getSurname()).matches() |
|
else if(!userService.checkIfCorrect(userDTO,false)){
|
||||||
!pEmail.matcher(userDTO.getEmail()).matches() | !pLogin.matcher(userDTO.getLogin()).matches() |
|
|
||||||
!pPassword.matcher(userDTO.getPassword()).matches()){
|
|
||||||
|
|
||||||
System.out.println(userDTO.getName() + " " + pName.matcher(userDTO.getName()).matches());
|
|
||||||
System.out.println(userDTO.getSurname() + " " + pSurname.matcher(userDTO.getSurname()).matches());
|
|
||||||
System.out.println(userDTO.getEmail() + " " + pEmail.matcher(userDTO.getEmail()).matches());
|
|
||||||
System.out.println(userDTO.getLogin() + " " + pLogin.matcher(userDTO.getLogin()).matches());
|
|
||||||
System.out.println(userDTO.getPassword() + " " + pPassword.matcher(userDTO.getPassword()).matches());
|
|
||||||
|
|
||||||
map.put("message","Niepoprawny login lub hasło");
|
map.put("message","Niepoprawny login lub hasło");
|
||||||
|
|
||||||
@ -97,11 +82,8 @@ public class UserController {
|
|||||||
|
|
||||||
else{
|
else{
|
||||||
|
|
||||||
|
|
||||||
User registerUser = new User();
|
User registerUser = new User();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
registerUser.setName(userDTO.getName());
|
registerUser.setName(userDTO.getName());
|
||||||
registerUser.setSurname(userDTO.getSurname());
|
registerUser.setSurname(userDTO.getSurname());
|
||||||
registerUser.setEmail(userDTO.getEmail());
|
registerUser.setEmail(userDTO.getEmail());
|
||||||
@ -111,18 +93,14 @@ public class UserController {
|
|||||||
|
|
||||||
String pass = this.bCryptPasswordEncoder.encode(userDTO.getPassword());
|
String pass = this.bCryptPasswordEncoder.encode(userDTO.getPassword());
|
||||||
|
|
||||||
System.out.println(pass);
|
|
||||||
registerUser.setPassword(pass);
|
registerUser.setPassword(pass);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Role role = this.roleService.getRoleByName(userDTO.getRoleDTO().getName());
|
Role role = this.roleService.getRoleByName(userDTO.getRoleDTO().getName());
|
||||||
registerUser.setRole(role);
|
registerUser.setRole(role);
|
||||||
|
|
||||||
|
|
||||||
this.userService.addUser(registerUser);
|
this.userService.addUser(registerUser);
|
||||||
map.put("message", "Zostałeś pomyślnie zarejestrowany");
|
map.put("message", "Zostałeś pomyślnie zarejestrowany");
|
||||||
httpServletResponse.setStatus(201);
|
httpServletResponse.setStatus(200);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,45 +108,92 @@ public class UserController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('COMP','IND')")
|
@PreAuthorize("hasAnyAuthority('COMP','IND')")
|
||||||
@RequestMapping(value="/profile/{id}",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
@RequestMapping(value="/profile",method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public ResponseEntity<Map<String,Object>> getProfileInfo(HttpServletRequest request,
|
@ResponseBody
|
||||||
@PathVariable int id){
|
public Map<String,Object> getMyProfile(HttpServletRequest request,HttpServletResponse httpServletResponse){
|
||||||
|
|
||||||
|
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String,Object> map = new HashMap<>();
|
||||||
UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
Optional<User> user = userService.getUsersByLogin(userDetails.getUsername());
|
Optional<User> user = userService.getUsersByLogin(userDetails.getUsername());
|
||||||
int userId = user.get().getId();
|
|
||||||
|
|
||||||
String userRole = user.get().getRole().getName();
|
if (user.isPresent()) {
|
||||||
|
User currentUser = user.get();
|
||||||
|
|
||||||
|
|
||||||
Object token = request.getAttribute("token");
|
Object token = request.getAttribute("token");
|
||||||
map.put("token",token);
|
|
||||||
|
map.put("token", tokenHelper.refreshToken(token.toString()));
|
||||||
|
|
||||||
|
map.put("profil", this.generatorDTO.generateUserDTO(currentUser));
|
||||||
|
httpServletResponse.setStatus(200);
|
||||||
|
|
||||||
|
|
||||||
User userProfile = this.userService.getUserById(id);
|
|
||||||
if(userProfile!=null) {
|
|
||||||
|
|
||||||
String userProfileRole = userProfile.getRole().getName();
|
|
||||||
|
|
||||||
if (userId == id) {
|
|
||||||
map.put("profil", this.generatorDTO.generateUserDTO(userProfile));
|
|
||||||
return new ResponseEntity<Map<String, Object>>(map, HttpStatus.OK);
|
|
||||||
}else {
|
|
||||||
map.put("message", "Nie masz dostępu do tej strony");
|
|
||||||
return new ResponseEntity<Map<String, Object>>(map, HttpStatus.BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}else{
|
|
||||||
map.put("message", "Profil nie istnieje");
|
|
||||||
return new ResponseEntity<Map<String, Object>>(map, HttpStatus.BAD_REQUEST);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
map.put("message", "Profil nie istnieje");
|
||||||
|
httpServletResponse.setStatus(404);
|
||||||
|
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasAnyAuthority('COMP','IND')")
|
||||||
|
@RequestMapping(value="/profile",method = RequestMethod.PUT,produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
@ResponseBody
|
||||||
|
public Map<String,Object> editMyProfile(@RequestBody @Valid @NotNull UserDTO userDTO,HttpServletRequest request,HttpServletResponse httpServletResponse){
|
||||||
|
|
||||||
|
Map<String,Object> map = new HashMap<>();
|
||||||
|
UserDetails userDetails = (UserDetails)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||||
|
Optional<User> user = userService.getUsersByLogin(userDetails.getUsername());
|
||||||
|
|
||||||
|
if (user.isPresent()) {
|
||||||
|
User currentUser = user.get();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Object token = request.getAttribute("token");
|
||||||
|
|
||||||
|
map.put("token", tokenHelper.refreshToken(token.toString()));
|
||||||
|
|
||||||
|
if(userService.checkIfCorrect(userDTO,true)){
|
||||||
|
|
||||||
|
|
||||||
|
currentUser.setName(userDTO.getName());
|
||||||
|
currentUser.setSurname(userDTO.getSurname());
|
||||||
|
currentUser.setDatebirth(userDTO.getDatebirth());
|
||||||
|
currentUser.setGender(userDTO.getGender());
|
||||||
|
currentUser.setEmail(userDTO.getEmail());
|
||||||
|
|
||||||
|
map.put("profil", this.generatorDTO.generateUserDTO(userService.addUser(currentUser)));
|
||||||
|
httpServletResponse.setStatus(200);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
map.put("message", "Błędne dane");
|
||||||
|
httpServletResponse.setStatus(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
|
||||||
|
map.put("message", "Profil nie istnieje");
|
||||||
|
httpServletResponse.setStatus(404);
|
||||||
|
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package project.services;
|
package project.services;
|
||||||
|
|
||||||
|
import project.DTO.UserDTO;
|
||||||
import project.model.User;
|
import project.model.User;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -15,6 +16,7 @@ public interface UserService {
|
|||||||
public void deleteUser(int id);
|
public void deleteUser(int id);
|
||||||
public User getUserById(int id);
|
public User getUserById(int id);
|
||||||
public List<User> getAllUsers();
|
public List<User> getAllUsers();
|
||||||
|
public boolean checkIfCorrect(UserDTO userDTO,boolean edit);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import project.DTO.UserDTO;
|
||||||
import project.model.CustomUserDetails;
|
import project.model.CustomUserDetails;
|
||||||
import project.model.User;
|
import project.model.User;
|
||||||
import project.repositories.UserRepository;
|
import project.repositories.UserRepository;
|
||||||
@ -20,6 +21,7 @@ import javax.servlet.http.HttpSession;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static org.springframework.security.web.context.HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY;
|
import static org.springframework.security.web.context.HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY;
|
||||||
|
|
||||||
@ -78,4 +80,28 @@ public class UserServiceImpl implements UserService,UserDetailsService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean checkIfCorrect(UserDTO userDTO,boolean edit){
|
||||||
|
Pattern pName =Pattern.compile("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,15}$");
|
||||||
|
Pattern pSurname =Pattern.compile("^[A-Z][a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{2,20}$");
|
||||||
|
Pattern pEmail =Pattern.compile("^[a-z]+[0-9]*@([a-z]{2,10}\\.)+[a-z]{2,5}$");
|
||||||
|
Pattern pLogin =Pattern.compile("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]+[0-9\\-\\_]*){5,20}$");
|
||||||
|
Pattern pPassword =Pattern.compile("^([a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż]{5,}[0-9]{5,}[a-zA-ZĄąĆćĘꣳŃńÓ󌜏źŻż0-9]*)+$");
|
||||||
|
|
||||||
|
if(!pName.matcher(userDTO.getName()).matches() | !pSurname.matcher(userDTO.getSurname()).matches() |
|
||||||
|
!pEmail.matcher(userDTO.getEmail()).matches() ) {
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}else if(!edit){
|
||||||
|
if(!pLogin.matcher(userDTO.getLogin()).matches() |
|
||||||
|
!pPassword.matcher(userDTO.getPassword()).matches()){
|
||||||
|
return false;
|
||||||
|
}else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user