This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class IdentityExtensions | |
{ | |
public static CustomIdentity ToCustomIdentity(this IIdentity identity) | |
{ | |
return (CustomIdentity) identity; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Extra user custom data | |
/// </summary> | |
public class UserIdentity | |
{ | |
public int UserId { get; set; } | |
public string Username { get; set; } | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class FormsAuthenticationService : IFormsAuthenticationService | |
{ | |
public void SignIn(UserIdentity user, bool createPersistentCookie) | |
{ | |
//UserData is stored as json | |
string userData = JsonSerializer.SerializeToString<UserIdentity>(user); | |
FormsAuthenticationTicket authTicket = new | |
FormsAuthenticationTicket(1, //version | |
user.UserId.ToString(), // user name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static int CountSorted<T>(this List<T> list, T item) where T : IComparable | |
{ | |
//find random index of the item | |
int index = list.BinarySearch(item); | |
//if item isn't found, just return -1 | |
if (index < 0) | |
return -1; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<canvas id="MyCanvas" width="300" height="300"> | |
</canvas> | |
<img id="MyImg"/> | |
<script> | |
function drawAndConvertStuff(canvas) { | |
var canvasContext = canvas.getContext('2d'); | |
//draw a black box |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@using (Html.BeginForm()) | |
{ | |
<div id="RegBox" style="display: none;"> | |
@Html.LabelFor(m => Model.Name) | |
@Html.TextBoxFor(m => Model.Name) | |
@Html.ValidationMessageFor(m => m.Name) | |
</div> | |
<div id="LoginBox"> | |
@Html.LabelFor(m => Model.Email) |
NewerOlder