-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
UserAuth.cs
93 lines (86 loc) · 3.08 KB
/
UserAuth.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using ServiceStack.Common;
using ServiceStack.DataAnnotations;
namespace ServiceStack.ServiceInterface.Auth
{
public class UserAuth
{
public UserAuth()
{
this.Roles = new List<string>();
this.Permissions = new List<string>();
}
[AutoIncrement]
public int Id { get; set; }
public string UserName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string DisplayName { get; set; }
public string Email { get; set; }
public string Salt { get; set; }
public string PasswordHash { get; set; }
public List<string> Roles { get; set; }
public List<string> Permissions { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public void PopulateMissing(UserOAuthProvider authProvider)
{
if (!authProvider.FirstName.IsNullOrEmpty())
this.FirstName = authProvider.FirstName;
if (!authProvider.LastName.IsNullOrEmpty())
this.LastName = authProvider.LastName;
if (!authProvider.DisplayName.IsNullOrEmpty())
this.DisplayName = authProvider.DisplayName;
if (!authProvider.Email.IsNullOrEmpty())
this.Email = authProvider.Email;
}
}
public class UserOAuthProvider : IOAuthTokens
{
public UserOAuthProvider()
{
this.Items = new Dictionary<string, string>();
}
[AutoIncrement]
public int Id { get; set; }
public int UserAuthId { get; set; }
public string Provider { get; set; }
public string UserId { get; set; }
public string UserName { get; set; }
public string DisplayName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; set; }
public string RequestToken { get; set; }
public string RequestTokenSecret { get; set; }
public Dictionary<string, string> Items { get; set; }
public string AccessToken { get; set; }
public string AccessTokenSecret { get; set; }
public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; }
public void PopulateMissing(IOAuthTokens withTokens)
{
if (!withTokens.UserId.IsNullOrEmpty())
this.UserId = withTokens.UserId;
if (!withTokens.UserName.IsNullOrEmpty())
this.UserName = withTokens.UserName;
if (!withTokens.RequestToken.IsNullOrEmpty())
this.RequestToken = withTokens.RequestToken;
if (!withTokens.RequestTokenSecret.IsNullOrEmpty())
this.RequestTokenSecret = withTokens.RequestTokenSecret;
if (!withTokens.AccessToken.IsNullOrEmpty())
this.AccessToken = withTokens.AccessToken;
if (!withTokens.AccessTokenSecret.IsNullOrEmpty())
this.AccessTokenSecret = withTokens.AccessTokenSecret;
if (!withTokens.DisplayName.IsNullOrEmpty())
this.DisplayName = withTokens.DisplayName;
if (!withTokens.FirstName.IsNullOrEmpty())
this.FirstName = withTokens.FirstName;
if (!withTokens.LastName.IsNullOrEmpty())
this.LastName = withTokens.LastName;
if (!withTokens.Email.IsNullOrEmpty())
this.Email = withTokens.Email;
}
}
}