public static TwitterUser Map([CanBeNull] DatabaseUser user, [CanBeNull] UserDescEnts dents, [CanBeNull] UserUrlEnts uents) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (dents == null) { throw new ArgumentNullException(nameof(dents)); } if (uents == null) { throw new ArgumentNullException(nameof(uents)); } var dent = dents.Memoize(); var uent = uents.Memoize(); var ent = dent.Cast <DatabaseEntity>().Concat(uent); if (ent.Any(e => e.ParentId != user.Id)) { throw new ArgumentException("ID mismatched between user and entities."); } return(new TwitterUser(user.Id, user.ScreenName, user.Name, user.Description, user.Location, user.Url, user.IsDefaultProfileImage, user.ProfileImageUri.ParseUri(), user.ProfileBackgroundImageUri.ParseUri(), user.ProfileBannerUri.ParseUri(), user.IsProtected, user.IsVerified, user.IsTranslator, user.IsContributorsEnabled, user.IsGeoEnabled, user.StatusesCount, user.FollowingsCount, user.FollowersCount, user.FavoritesCount, user.ListedCount, user.Language, user.CreatedAt, uent.Select(Map).OfType <TwitterUrlEntity>().ToArray(), dent.Select(Map).ToArray())); }
public RegisterPageViewModel() { user = new UserModel(); db = new DatabaseUser(); CommandButtonRegister = new Command(CommandButtonClicked); LabelErrorResponseIsVisible = false; LabelErrorResponse = null; }
private JwtSecurityToken MakeToken(DatabaseUser user, IList <string> roles) { var claims = MakeClaims(user, roles); var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_authOptions.Value.Secret)); return(new JwtSecurityToken( expires: DateTime.UtcNow.AddMinutes(_authOptions.Value.Expiration), claims: claims, signingCredentials: new SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256))); }
private static UserCredentialsModel MakeUserCredentials(SecurityToken token, DatabaseUser user) { return(new UserCredentialsModel() { AccessToken = new JwtSecurityTokenHandler().WriteToken(token), Name = user.Name, Email = user.Email, IsAdmin = user.IsAdmin }); }
private static IEnumerable <Claim> MakeClaims(DatabaseUser user, IList <string> roles) { var claims = new List <Claim> { new Claim(ClaimTypes.Name, user.Id), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; AddRoles(claims, roles); return(claims); }
private dynamic PostLogin(dynamic parameters) { var loginParams = this.Bind<LoginParams>(); DatabaseUser db = new DatabaseUser(); var user = db.Users.FirstOrDefault(x => x.UserName.Equals(loginParams.LoginName) && x.Password.Equals(loginParams.Password)); if (user == null) { return View["account/loginerror"]; } return this.Login(user.UserId, fallbackRedirectUrl: "~/auth"); }