Skip to content

Instantly share code, notes, and snippets.

@christopherhouse
Created December 13, 2013 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christopherhouse/7949559 to your computer and use it in GitHub Desktop.
Save christopherhouse/7949559 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MobileServices;
using ThirteenDaysAWeek.AzureCustomAuth.Models;
using ThirteenDaysAWeek.AzureCustomAuth.Handlers;
using ThirteenDaysAWeek.AzureCustomAuth.Factories;
namespace ThirteenDaysAWeek.AzureCustomAuth.Services
{
public class AccountService
{
public static string AuthenticationToken { get; set; }
public async Task Register(string username, string password, string email)
{
await DoInsert(username, password, email, false);
}
public async Task<bool> Login(string username, string password)
{
bool result;
try
{
await DoInsert(username, password, null, true);
result = true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
result = false;
}
return result;
}
private async Task DoInsert(string username, string password, string email, bool isLogin)
{
Account account = new Account {
Username = username,
Password = password,
Email = email
};
using (AuthenticationHandler handler = new AuthenticationHandler()) {
using (MobileServiceClient client = MobileServiceClientFactory.CreateClient(handler)) {
var table = client.GetTable<Account>();
Dictionary<string, string> parameters = new Dictionary<string, string> {
{ "login", isLogin.ToString().ToLower()}
};
await table.InsertAsync(account, parameters);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment