File tree Expand file tree Collapse file tree 5 files changed +37
-13
lines changed
Expand file tree Collapse file tree 5 files changed +37
-13
lines changed Original file line number Diff line number Diff line change 11#r " ./packages/email/Newtonsoft.Json/lib/net45/Newtonsoft.Json.dll"
2- open Newtonsoft. Json
2+ #r " ./packages/BCrypt.Net-Next/lib/net452/BCrypt.Net-Next.dll "
33
4- let placeHolders =
5- Map.empty
6- .Add( " verification_code" , " 12323" )
4+ open BCrypt.Net
75
8- JsonConvert.SerializeObject( placeHolders)
6+
7+ BCrypt.InterrogateHash " $2a$10$e8IgrOqZx08UTwIZSbswAec7ospkD.E/JeySAWj19iDcksRDWE9y6"
Original file line number Diff line number Diff line change @@ -18,6 +18,13 @@ module Domain =
1818 }
1919 }
2020
21+ type LoginError =
22+ | UsernameNotFound
23+ | EmailNotVerified
24+ | PasswordMisMatch
25+ | Error of System.Exception
26+
27+ type Login = FindUser -> LoginRequest -> AsyncResult< User, LoginError>
2128
2229module Suave =
2330 open Suave
@@ -50,8 +57,7 @@ module Suave =
5057 | Success req ->
5158 return ! Successful.OK " TODO" ctx
5259 | Failure err ->
53- let viewModel =
54- { vm with Error = Some err}
60+ let viewModel = { vm with Error = Some err}
5561 return ! page " guest/login.liquid" viewModel ctx
5662 | Choice2Of2 err ->
5763 let viewModel =
Original file line number Diff line number Diff line change 4141 </ItemGroup >
4242 <ItemGroup >
4343 <Compile Include =" Chessie.fs" />
44- <Compile Include =" User.fs" />
4544 <Compile Include =" Db.fs" />
4645 <Compile Include =" Email.fs" />
46+ <Compile Include =" User.fs" />
4747 <Compile Include =" UserSignup.fs" />
4848 <Compile Include =" Auth.fs" />
4949 <Compile Include =" FsTweet.Web.fs" />
Original file line number Diff line number Diff line change @@ -49,4 +49,22 @@ type PasswordHash = private PasswordHash of string with
4949
5050 static member Create ( password : Password ) =
5151 BCrypt.HashPassword( password.Value)
52- |> PasswordHash
52+ |> PasswordHash
53+
54+ type UserEmail =
55+ | Verified of EmailAddress
56+ | NotVerified of EmailAddress
57+
58+ type User = {
59+ UserId : UserId
60+ Username : Username
61+ Email : UserEmail
62+ PasswordHash : PasswordHash
63+ }
64+
65+ type FindUser = Username -> AsyncResult< User option, System.Exception>
66+
67+
68+ module Persistence =
69+ open Database
70+ let findUser ( getDataCtx : GetDataContext ) ( username : Username ) = ()
Original file line number Diff line number Diff line change @@ -118,7 +118,8 @@ module Persistence =
118118 UsernameAlreadyExists
119119 | _ -> Error ex
120120
121- let createUser ( getDataCtx : GetDataContext ) createUserReq = asyncTrial {
121+ let createUser ( getDataCtx : GetDataContext )
122+ ( createUserReq : CreateUserRequest ) = asyncTrial {
122123 let ctx = getDataCtx ()
123124 let users = ctx.Public.Users
124125
@@ -252,13 +253,13 @@ module Suave =
252253 let result =
253254 UserSignupRequest.TryCreate ( vm.Username, vm.Password, vm.Email)
254255 match result with
255- | Ok ( userSignupReq, _) ->
256+ | Success userSignupReq ->
256257 let userSignupAsyncResult = signupUser userSignupReq
257258 let! webpart =
258259 handleUserSignupAsyncResult vm userSignupAsyncResult
259260 return ! webpart ctx
260- | Bad msgs ->
261- let viewModel = { vm with Error = Some ( List.head msgs ) }
261+ | Failure msg ->
262+ let viewModel = { vm with Error = Some msg }
262263 return ! page signupTemplatePath viewModel ctx
263264 | Choice2Of2 err ->
264265 let viewModel = { emptyUserSignupViewModel with Error = Some err}
You can’t perform that action at this time.
0 commit comments