mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-24 18:29:10 +00:00
- NioTSO client isn't needed because we're using RayLib - Added FreeSO's API server to handle most backend operations
57 lines
1.8 KiB
C#
Executable file
57 lines
1.8 KiB
C#
Executable file
using System;
|
|
using System.Linq;
|
|
using Dapper;
|
|
using FSO.Server.Common;
|
|
|
|
namespace FSO.Server.Database.DA.EmailConfirmation
|
|
{
|
|
public class SqlEmailConfirmations : AbstractSqlDA, IEmailConfirmations
|
|
{
|
|
public SqlEmailConfirmations(ISqlContext context) : base(context)
|
|
{
|
|
|
|
}
|
|
|
|
public EmailConfirmation GetByToken(string token)
|
|
{
|
|
var confirm = Context.Connection.Query<EmailConfirmation>("SELECT * FROM fso_email_confirm WHERE token = @token", new { token = token }).FirstOrDefault();
|
|
|
|
if(confirm==null) { return null; }
|
|
|
|
if(Epoch.Now > confirm.expires)
|
|
{
|
|
Remove(confirm.token);
|
|
return null;
|
|
}
|
|
|
|
return confirm;
|
|
}
|
|
|
|
public EmailConfirmation GetByEmail(string email, ConfirmationType type)
|
|
{
|
|
var confirm = Context.Connection.Query<EmailConfirmation>("SELECT * FROM fso_email_confirm WHERE email = @email AND type = @type", new { email = email, type = type }).FirstOrDefault();
|
|
|
|
if (confirm == null) { return null; }
|
|
|
|
if (Epoch.Now > confirm.expires)
|
|
{
|
|
Remove(confirm.token);
|
|
return null;
|
|
}
|
|
|
|
return confirm;
|
|
}
|
|
|
|
public string Create(EmailConfirmation confirm)
|
|
{
|
|
confirm.token = Guid.NewGuid().ToString().ToUpper();
|
|
Context.Connection.Execute("INSERT INTO fso_email_confirm (type, email, token, expires) VALUES (@type, @email, @token, @expires)", confirm);
|
|
return confirm.token;
|
|
}
|
|
|
|
public void Remove(string token)
|
|
{
|
|
Context.Connection.Execute("DELETE FROM fso_email_confirm WHERE token = @token", new { token = token });
|
|
}
|
|
}
|
|
}
|