Skip to content

Commit a94bc95

Browse files
committed
adds login user domain type
1 parent 9f2f590 commit a94bc95

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

script.fsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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"

src/FsTweet.Web/Auth.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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

2229
module 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 =

src/FsTweet.Web/FsTweet.Web.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
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" />

src/FsTweet.Web/User.fs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff 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) = ()

src/FsTweet.Web/UserSignup.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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}

0 commit comments

Comments
 (0)