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
132 lines (119 loc) · 5.34 KB
/
UserAuth.cs
File metadata and controls
132 lines (119 loc) · 5.34 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
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 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 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 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)
{
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.PrimaryEmail = authProvider.Email;
}
}
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 DisplayName { get; set; }
public virtual string FirstName { get; set; }
public virtual string LastName { get; set; }
public virtual string Email { 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 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 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.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;
}
}
}