forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAuth.cs
More file actions
204 lines (188 loc) · 9.04 KB
/
UserAuth.cs
File metadata and controls
204 lines (188 loc) · 9.04 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
using System;
using System.Collections.Generic;
using ServiceStack.Common;
using ServiceStack.DataAnnotations;
using ServiceStack.Text;
namespace ServiceStack.ServiceInterface.Auth
{
public class UserAuth
{
public UserAuth()
{
this.Roles = new List<string>();
this.Permissions = new List<string>();
}
[AutoIncrement]
public virtual int Id { get; set; }
public virtual string UserName { get; set; }
public virtual string Email { get; set; }
public virtual string PrimaryEmail { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string DisplayName { get; set; }
public virtual DateTime? BirthDate { get; set; }
public virtual string BirthDateRaw { get; set; }
public virtual string Country { get; set; }
public virtual string Culture { get; set; }
public virtual string FullName { get; set; }
public virtual string Gender { get; set; }
public virtual string Language { get; set; }
public virtual string MailAddress { get; set; }
public virtual string Nickname { get; set; }
public virtual string PostalCode { get; set; }
public virtual string TimeZone { get; set; }
public virtual string Salt { get; set; }
public virtual string PasswordHash { get; set; }
public virtual string DigestHA1Hash { get; set; }
public virtual List<string> Roles { get; set; }
public virtual List<string> Permissions { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual DateTime ModifiedDate { get; set; }
//Custom Reference Data
public virtual int? RefId { get; set; }
public virtual string RefIdStr { get; set; }
public virtual Dictionary<string, string> Meta { get; set; }
public virtual T Get<T>()
{
string str = null;
if (Meta != null) Meta.TryGetValue(typeof(T).Name, out str);
return str == null ? default(T) : TypeSerializer.DeserializeFromString<T>(str);
}
public virtual void Set<T>(T value)
{
if (Meta == null) Meta = new Dictionary<string, string>();
Meta[typeof(T).Name] = TypeSerializer.SerializeToString(value);
}
public virtual void PopulateMissing(UserOAuthProvider authProvider)
{
//Don't explicitly override after if values exist
if (!authProvider.DisplayName.IsNullOrEmpty() && this.DisplayName.IsNullOrEmpty())
this.DisplayName = authProvider.DisplayName;
if (!authProvider.Email.IsNullOrEmpty() && this.PrimaryEmail.IsNullOrEmpty())
this.PrimaryEmail = authProvider.Email;
if (!authProvider.FirstName.IsNullOrEmpty())
this.FirstName = authProvider.FirstName;
if (!authProvider.LastName.IsNullOrEmpty())
this.LastName = authProvider.LastName;
if (!authProvider.FullName.IsNullOrEmpty())
this.FullName = authProvider.FullName;
if (authProvider.BirthDate != null)
this.BirthDate = authProvider.BirthDate;
if (!authProvider.BirthDateRaw.IsNullOrEmpty())
this.BirthDateRaw = authProvider.BirthDateRaw;
if (!authProvider.Country.IsNullOrEmpty())
this.Country = authProvider.Country;
if (!authProvider.Culture.IsNullOrEmpty())
this.Culture = authProvider.Culture;
if (!authProvider.Gender.IsNullOrEmpty())
this.Gender = authProvider.Gender;
if (!authProvider.MailAddress.IsNullOrEmpty())
this.MailAddress = authProvider.MailAddress;
if (!authProvider.Nickname.IsNullOrEmpty())
this.Nickname = authProvider.Nickname;
if (!authProvider.PostalCode.IsNullOrEmpty())
this.PostalCode = authProvider.PostalCode;
if (!authProvider.TimeZone.IsNullOrEmpty())
this.TimeZone = authProvider.TimeZone;
}
}
public class UserOAuthProvider : IOAuthTokens
{
public UserOAuthProvider()
{
this.Items = new Dictionary<string, string>();
}
[AutoIncrement]
public virtual int Id { get; set; }
public virtual int UserAuthId { get; set; }
public virtual string Provider { get; set; }
public virtual string UserId { get; set; }
public virtual string UserName { get; set; }
public virtual string FullName { get; set; }
public virtual string DisplayName { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Email { get; set; }
public virtual DateTime? BirthDate { get; set; }
public virtual string BirthDateRaw { get; set; }
public virtual string Country { get; set; }
public virtual string Culture { get; set; }
public virtual string Gender { get; set; }
public virtual string Language { get; set; }
public virtual string MailAddress { get; set; }
public virtual string Nickname { get; set; }
public virtual string PostalCode { get; set; }
public virtual string TimeZone { get; set; }
public virtual string RefreshToken { get; set; }
public virtual DateTime? RefreshTokenExpiry { get; set; }
public virtual string RequestToken { get; set; }
public virtual string RequestTokenSecret { get; set; }
public virtual Dictionary<string, string> Items { get; set; }
public virtual string AccessToken { get; set; }
public virtual string AccessTokenSecret { get; set; }
public virtual DateTime CreatedDate { get; set; }
public virtual DateTime ModifiedDate { get; set; }
//Custom Reference Data
public virtual int? RefId { get; set; }
public virtual string RefIdStr { get; set; }
public virtual Dictionary<string, string> Meta { get; set; }
public virtual T Get<T>()
{
string str = null;
if (Meta != null) Meta.TryGetValue(typeof(T).Name, out str);
return str == null ? default(T) : TypeSerializer.DeserializeFromString<T>(str);
}
public virtual void Set<T>(T value)
{
if (Meta == null) Meta = new Dictionary<string, string>();
Meta[typeof(T).Name] = TypeSerializer.SerializeToString(value);
}
public virtual void PopulateMissing(IOAuthTokens withTokens)
{
if (!withTokens.UserId.IsNullOrEmpty())
this.UserId = withTokens.UserId;
if (!withTokens.UserName.IsNullOrEmpty())
this.UserName = withTokens.UserName;
if (!withTokens.RefreshToken.IsNullOrEmpty())
this.RefreshToken = withTokens.RefreshToken;
if (withTokens.RefreshTokenExpiry.HasValue)
this.RefreshTokenExpiry = withTokens.RefreshTokenExpiry;
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;
if (!withTokens.FullName.IsNullOrEmpty())
this.FullName = withTokens.FullName;
if (withTokens.BirthDate != null)
this.BirthDate = withTokens.BirthDate;
if (!withTokens.BirthDateRaw.IsNullOrEmpty())
this.BirthDateRaw = withTokens.BirthDateRaw;
if (!withTokens.Country.IsNullOrEmpty())
this.Country = withTokens.Country;
if (!withTokens.Culture.IsNullOrEmpty())
this.Culture = withTokens.Culture;
if (!withTokens.Gender.IsNullOrEmpty())
this.Gender = withTokens.Gender;
if (!withTokens.MailAddress.IsNullOrEmpty())
this.MailAddress = withTokens.MailAddress;
if (!withTokens.Nickname.IsNullOrEmpty())
this.Nickname = withTokens.Nickname;
if (!withTokens.PostalCode.IsNullOrEmpty())
this.PostalCode = withTokens.PostalCode;
if (!withTokens.TimeZone.IsNullOrEmpty())
this.TimeZone = withTokens.TimeZone;
}
}
}