Esempio n. 1
0
 /// <summary>
 /// Create identity from a cookie data
 /// </summary>
 /// <param name="cookieString">String stored in cookie, created via ToJson method</param>
 /// <returns>Instance of identity</returns>
 public static ICustomIdentity FromJson(string cookieString)
 {
     IdentityRepresentation serializedIdentity;
     using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(cookieString)))
     {
         var jsonSerializer = new DataContractJsonSerializer(typeof(IdentityRepresentation));
         serializedIdentity = jsonSerializer.ReadObject(stream) as IdentityRepresentation;
     }
     var identity = new CustomIdentity()
     {
         IsAuthenticated = serializedIdentity.IsAuthenticated,
         Name = serializedIdentity.Name,
         Roles = serializedIdentity.Roles
             .Split(new[] { "|" }, StringSplitOptions.RemoveEmptyEntries)
     };
     return identity;
 }
Esempio n. 2
0
        /// <summary>
        /// Authenticate and get identity out with roles
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="password">Password</param>
        /// <returns>Instance of identity</returns>
        public static CustomIdentity GetCustomIdentity(string email, string password)
        {
            var identity = new CustomIdentity();
            var uServcice = new UserService();

            bool loginResponse = uServcice.UserLogin(email, password);

            if (loginResponse)
            {
                identity.IsAuthenticated = true;
                identity.Name = email;
                var roles = new[] { "admin" };
                identity.Roles = roles;

                return identity;
            }
            return identity;
        }