Skip to content

Commit

Permalink
Sign in with Google
Browse files Browse the repository at this point in the history
  • Loading branch information
ciukstar committed Dec 30, 2023
1 parent 0b48b87 commit e2f3b1e
Show file tree
Hide file tree
Showing 44 changed files with 507 additions and 236 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ salon.cabal
node_modules/
package-lock.json
package.json
build-demo-en.sh
build-demo-fr.sh
build-demo-ro.sh
build-demo-ru.sh
deploy-demo-en.sh
deploy-demo-fr.sh
deploy-demo-ro.sh
Expand Down
10 changes: 9 additions & 1 deletion config/models.persistentmodels
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,16 @@ UserPhoto
mime Text
UniqueUserPhoto user

UserCred
user UserId OnDeleteCascade
name Text
val Text
UniqueUserCred user name

User
name Text
password Text
authType AuthenticationType
password Text Maybe
admin Bool
analyst Bool
blocked Bool
Expand All @@ -156,6 +163,7 @@ User
UniqueUser name
deriving Typeable


Brand
business BusinessId OnDeleteCascade
mark ByteString Maybe
Expand Down
4 changes: 2 additions & 2 deletions config/routes.yesodroutes
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@
/auth AuthR Auth getAuth

/photo-placeholder PhotoPlaceholderR GET
/favicon.ico FaviconR GET
/robots.txt RobotsR GET
/favicon.ico FaviconR GET
/robots.txt RobotsR GET

/manifest.json WebAppManifestR GET
/sitemap.xml SitemapR GET
1 change: 1 addition & 0 deletions messages/en.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SignInWithGoogle: Sign in with Google
Cleared: Cleared
InvalidStoreType: Invalid store type
Initialization: Initialization
Expand Down
1 change: 1 addition & 0 deletions messages/fr.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SignInWithGoogle: Connectez-vous avec Google
Cleared: Effacé
InvalidStoreType: Type de stockage invalide
Initialization: Initialisation
Expand Down
1 change: 1 addition & 0 deletions messages/ro.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SignInWithGoogle: Conectați-vă cu Google
Cleared: S-a șters
InvalidStoreType: Tip de stocare nevalid
Initialization: Inițializare
Expand Down
1 change: 1 addition & 0 deletions messages/ru.msg
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
SignInWithGoogle: Войти через Google
Cleared: Очищено
InvalidStoreType: Неверный тип хранилища
Initialization: Инициализация
Expand Down
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies:
- http-client
- safe-exceptions
- HPDF
- yesod-auth-oauth2


# The library contains all of our application code. The executable
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Billing.hs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ renderIvoiceHtml :: Maybe (Entity User)
renderIvoiceHtml customer employee invoice items = [ihamlet|
<h1>_{MsgAppName}
<h2>_{MsgInvoice}
$maybe Entity _ (User uname _ _ _ _ _ cname cemail) <- customer
$maybe Entity _ (User uname _ _ _ _ _ _ cname cemail) <- customer
$maybe Entity _ (Staff ename _ _ _ eemail _) <- employee
$maybe Entity _ (Invoice _ _ no status day due) <- invoice
<table cellspacing=0 cellpadding=10 border=0>
Expand Down
7 changes: 5 additions & 2 deletions src/Admin/Staff.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ import Model
, ServiceId, Service (Service)
, UserId, User (User), UserPhoto (UserPhoto)
, EmplStatus (EmplStatusUnavailable, EmplStatusAvailable)
, SortOrder (SortOrderAsc, SortOrderDesc)
, SortOrder (SortOrderAsc, SortOrderDesc), AuthenticationType (UserAuthTypePassword)
)

import Settings.StaticFiles (img_add_photo_alternate_FILL0_wght400_GRAD0_opsz48_svg)
Expand Down Expand Up @@ -663,7 +663,10 @@ formUser empl extra = do
, fsTooltip = Nothing, fsId = Nothing, fsName = Nothing
, fsAttrs = [("class","mdc-text-field__input")]
} (staffEmail . entityVal <$> empl)
let r = User <$> nameR <*> passR <*> adminR <*> analystR <*> blockedR <*> deletedR <*> fnameR <*> emailR

let r = User <$> nameR <*> pure UserAuthTypePassword <*> (pure <$> passR) <*> adminR
<*> analystR <*> blockedR <*> deletedR <*> fnameR <*> emailR

let w = [whamlet|
#{extra}
$forall v <- [nameV,passV]
Expand Down
21 changes: 11 additions & 10 deletions src/Admin/Users.hs
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,16 @@ import Foundation
import Model
( UserId
, User
( User, userName, userPassword, userFullName, userEmail, userAdmin
( User, userName, userFullName, userEmail, userAdmin
, userAnalyst, userBlocked, userRemoved
)
, UserPhoto (UserPhoto)
, EntityField
( UserId, UserName, UserFullName, UserEmail, UserPhotoPhoto
, UserPhotoMime, UserPassword, UserAdmin, StaffUser, UserAnalyst
, UserBlocked, UserRemoved
, UserBlocked, UserRemoved, UserAuthType
)
, Staff
, Staff, AuthenticationType (UserAuthTypePassword)
)

import Settings.StaticFiles (img_add_photo_alternate_FILL0_wght400_GRAD0_opsz48_svg)
Expand Down Expand Up @@ -177,7 +177,7 @@ postUserPwdResetR uid = do
FormSuccess (r,_) -> do
pwd <- liftIO $ decodeUtf8 <$> makePassword (encodeUtf8 r) 17
runDB $ update $ \x -> do
set x [UserPassword =. val pwd]
set x [UserPassword =. val (pure pwd)]
where_ $ x ^. UserId ==. val uid
addMessageI "info" MsgPasswordChanged
redirect $ AdminR $ UserR uid
Expand Down Expand Up @@ -233,7 +233,7 @@ $case r
<i.material-symbols-outlined>close
$of _

$maybe Entity uid (User name _ _ _ _ _ _ _) <- user
$maybe Entity uid (User name _ _ _ _ _ _ _ _) <- user
<figure>
<img src=@{AccountPhotoR uid} width=56 heigt=56 alt=_{MsgPhoto}>
<figcaption>
Expand Down Expand Up @@ -286,9 +286,10 @@ postUserR uid = do
return x
((fr,fw),et) <- runFormPost $ formUserEdit user
case fr of
FormSuccess (User name _ admin analyst blocked removed fname email,mfi) -> do
FormSuccess (User name auth _ admin analyst blocked removed fname email,mfi) -> do
runDB $ update $ \x -> do
set x [ UserName =. val name
, UserAuthType =. val auth
, UserAdmin =. val admin
, UserAnalyst =. val analyst
, UserBlocked =. val blocked
Expand Down Expand Up @@ -328,8 +329,8 @@ postUsersR :: Handler Html
postUsersR = do
((fr,fw),et) <- runFormPost formUserCreate
case fr of
FormSuccess (r,mfi) -> do
uid <- setPassword (userPassword r) r >>= \u -> runDB $ insert u
FormSuccess (r@(User _ _ (Just pass) _ _ _ _ _ _),mfi) -> do
uid <- setPassword pass r >>= \u -> runDB $ insert u
addMessageI "info" MsgRecordAdded
case mfi of
Just fi -> do
Expand Down Expand Up @@ -413,7 +414,7 @@ formUserCreate extra = do
} Nothing

let r = (,)
<$> ( User <$> nameR <*> passR
<$> ( User <$> nameR <*> pure UserAuthTypePassword <*> (pure <$> passR)
<*> adminR <*> analystR <*> blockedR <*> removedR
<*> fnameR <*> emailR
) <*> photoR
Expand Down Expand Up @@ -539,7 +540,7 @@ formUserEdit user extra = do
} Nothing

let r = (,)
<$> ( User <$> nameR <*> FormSuccess "Nothing"
<$> ( User <$> nameR <*> pure UserAuthTypePassword <*> pure (pure "NOTHING")
<*> adminR <*> analystR <*> blockedR <*> removedR
<*> fnameR <*> emailR
)
Expand Down
34 changes: 22 additions & 12 deletions src/Demo/DemoDataEN.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import Database.Persist ( PersistStoreWrite(insert_, insert) )
import Model
( User
( User, userName, userPassword, userAdmin, userAnalyst, userBlocked
, userRemoved, userEmail, userFullName
, userRemoved, userEmail, userFullName, userAuthType
)
, UserPhoto (UserPhoto, userPhotoUser, userPhotoPhoto, userPhotoMime)
, Service
Expand Down Expand Up @@ -75,7 +75,7 @@ import Model
( ContactUs, contactUsBusiness, contactUsShowSchedule, contactUsShowMap
, contactUsLongitude, contactUsLatitude, contactUsHtml, contactUsShowAddress
)
, DayType (Weekday), PayMethod (PayAtVenue)
, DayType (Weekday), PayMethod (PayAtVenue), AuthenticationType (UserAuthTypePassword)
)

import Data.FileEmbed (embedFile)
Expand Down Expand Up @@ -169,7 +169,8 @@ populateEN = do

pass0 <- liftIO $ makePassword "root" 17
insert_ $ User { userName = "root"
, userPassword = decodeUtf8 pass0
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass0
, userAdmin = True
, userAnalyst = True
, userBlocked = False
Expand All @@ -180,7 +181,8 @@ populateEN = do

pass1 <- liftIO $ makePassword "johnnysmith" 17
let user1 = User { userName = "johnnysmith"
, userPassword = decodeUtf8 pass1
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass1
, userAdmin = False
, userAnalyst = True
, userBlocked = False
Expand Down Expand Up @@ -239,7 +241,8 @@ populateEN = do

pass2 <- liftIO $ makePassword "marylopez" 17
let user2 = User { userName = "marylopez"
, userPassword = decodeUtf8 pass2
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass2
, userAdmin = True
, userAnalyst = False
, userBlocked = False
Expand Down Expand Up @@ -271,7 +274,8 @@ populateEN = do

pass3 <- liftIO $ makePassword "johnjohnson" 17
let user3 = User { userName = "johnjohnson"
, userPassword = decodeUtf8 pass3
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass3
, userAdmin = False
, userAnalyst = False
, userBlocked = False
Expand Down Expand Up @@ -304,7 +308,8 @@ populateEN = do

pass4 <- liftIO $ makePassword "patriciabrown" 17
let user4 = User { userName = "patriciabrown"
, userPassword = decodeUtf8 pass4
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass4
, userAdmin = False
, userAnalyst = False
, userBlocked = False
Expand Down Expand Up @@ -337,7 +342,8 @@ populateEN = do

pass5 <- liftIO $ makePassword "chriswilson" 17
let user5 = User { userName = "chriswilson"
, userPassword = decodeUtf8 pass5
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass5
, userAdmin = False
, userAnalyst = False
, userBlocked = False
Expand Down Expand Up @@ -399,7 +405,8 @@ populateEN = do

pass8 <- liftIO $ makePassword "byoung" 17
let user8 = User { userName = "byoung"
, userPassword = decodeUtf8 pass8
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass8
, userAdmin = True
, userAnalyst = True
, userBlocked = False
Expand Down Expand Up @@ -501,7 +508,8 @@ populateEN = do

pass11 <- liftIO $ makePassword "ihughes" 17
let user11 = User { userName = "ihughes"
, userPassword = decodeUtf8 pass11
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass11
, userAdmin = False
, userAnalyst = False
, userBlocked = False
Expand Down Expand Up @@ -3021,7 +3029,8 @@ Body Shaping: Abdomen & waist, hips & thighs, legs & arms

pass6 <- liftIO $ makePassword "pattyofurniture" 17
c1 <- insert $ User { userName = "pattyofurniture"
, userPassword = decodeUtf8 pass6
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass6
, userAdmin = False
, userAnalyst = False
, userBlocked = False
Expand Down Expand Up @@ -3065,7 +3074,8 @@ Body Shaping: Abdomen & waist, hips & thighs, legs & arms

pass7 <- liftIO $ makePassword "raysin" 17
c2 <- insert $ User { userName = "raysin"
, userPassword = decodeUtf8 pass7
, userAuthType = UserAuthTypePassword
, userPassword = pure $ decodeUtf8 pass7
, userAdmin = False
, userAnalyst = False
, userBlocked = False
Expand Down
Loading

0 comments on commit e2f3b1e

Please sign in to comment.