forked from raquelsa/AspNet.Identity.MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserStore.EmailStore.cs
83 lines (73 loc) · 2.27 KB
/
UserStore.EmailStore.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
using Microsoft.AspNet.Identity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
namespace AspNet.Identity.MySQL
{
public partial class UserStore<TUser, TRole> : IUserEmailStore<TUser>
{
/// <summary>
/// Set email on user
/// </summary>
/// <param name="user"></param>
/// <param name="email"></param>
/// <returns></returns>
public Task SetEmailAsync(TUser user, string email)
{
user.Email = email;
userTable.Update(user);
return Task.FromResult(0);
}
/// <summary>
/// Get email from user
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public Task<string> GetEmailAsync(TUser user)
{
return Task.FromResult(user.Email);
}
/// <summary>
/// Get if user email is confirmed
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public Task<bool> GetEmailConfirmedAsync(TUser user)
{
return Task.FromResult(user.EmailConfirmed);
}
/// <summary>
/// Set when user email is confirmed
/// </summary>
/// <param name="user"></param>
/// <param name="confirmed"></param>
/// <returns></returns>
public Task SetEmailConfirmedAsync(TUser user, bool confirmed)
{
user.EmailConfirmed = confirmed;
userTable.Update(user);
return Task.FromResult(0);
}
/// <summary>
/// Get user by email
/// </summary>
/// <param name="email"></param>
/// <returns></returns>
public Task<TUser> FindByEmailAsync(string email)
{
if (String.IsNullOrEmpty(email))
{
throw new ArgumentNullException("email");
}
List<TUser> result = userTable.GetUserByEmail(email) as List<TUser>;
// Should I throw if > 1 user?
if (result != null && result.Count == 1)
{
return Task.FromResult<TUser>(result[0]);
}
return Task.FromResult<TUser>(null);
}
}
}