-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
UserAuth.cs
96 lines (89 loc) · 3.53 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
94
95
96
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 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; }
public virtual Dictionary<string, string> Meta { get; set; }
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; }
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;
}
}
}