public async Task Logout() { await authorizeApi.Logout(); userInfoCache = null; NotifyAuthenticationStateChanged(GetAuthenticationStateAsync()); }
private async Task <bool> AuthenticateUser(string accessToken, string state) { spotifyClient.AccessToken = accessToken; SpotifyCurrentUserProfile profile; try { profile = await spotifyClient.GetCurrentUserProfile(); } catch (Exception ex) { logger.LogWarning(ex, $"Failed to authenticate user due to Spotify exception. State: {state}"); throw; } UserInfo?userInfo = await cosmosAPI.GetUserInfo(state, profile.Id); if (userInfo == null) { return(false); } else { return(userInfo.UserId == profile.Id); } }
public async Task <MessageResponse> Handle(Message message) { var builder = new StringBuilder(); UserInfo?user = null; try { user = await _backendService.GetUserByTelegramIdAsync(message.From.Id); builder.AppendLine($"瞬Matataki 昵称: [{user.Name}]({_matatakiService.GetUserPageUrl(user.Id)})"); } catch { builder.AppendLine("没有绑定 Matataki"); } if (user?.IssuedTokens?.Length > 0) { var token = user.IssuedTokens[0]; builder.AppendLine($"Fan票 名称:[{token.Symbol} ({token.Name})]({_matatakiService.GetTokenPageUrl(user.IssuedTokens[0].Id)})"); } else { builder.AppendLine("没有发行 Fan 票"); } return(Markdown(builder.ToString())); }
private async Task <UserInfo> GetUserInfo() { if (userInfoCache != null && userInfoCache.IsAuthenticated) { return(userInfoCache); } userInfoCache = await authorizeApi.GetUserInfo(); return(userInfoCache); }
private void SpawnUser() { if (_userInfo == null) { return; } var user = _ownerUserFactory.Create(); user.Init((UserInfo)_userInfo); _userInfo = null; }
public void OnReceivedOurInfo(UserInfo?user) { var previousInfo = InfoReady; InfoReady = true; Info = user; // Null value doesn't trigger the initial callback, so we force that to happen here if (info == null && !previousInfo) { OnUserInfoChanged?.Invoke(this, info); } }
/// <summary> /// Call whenever receiving user info objects from the server. Used to react to our own user data changing /// </summary> /// <param name="user">The user info we received</param> public void OnReceivedAnUsersInfo(UserInfo?user) { if (!InfoReady || user == null) { return; } if (info == null || info.Id != user.Id) { return; } OnReceivedOurInfo(user); }
public JumpToUserVM(PixivClient client, IllustVMFactory illustVMFactory, UserInfo?userInfo = null) : base(illustVMFactory) { _client = client; if (userInfo != null) { UserInfo = userInfo; Load(userInfo); } async void Load(UserInfo user) { Refresh(); UserDetail = await user.GetDetailAsync().ConfigureAwait(true); } }
protected override Task <AuthenticateResult> HandleAuthenticateAsync() { UserInfo?user = null; AccountAuthenticationResponse authenticationResponse = AccountAuthenticationResponse.Unknown; string authHeader = Context.Request.Headers["Authorization"]; if (authHeader != null && authHeader.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase)) { // Convert the base64 string to a byte array. byte[] encodedUsernamePassword = Convert.FromBase64String(authHeader.Substring(6).TrimEnd()); // Transform the byte array into a string using the encoding defined in the HTTP specs. string[] usernamePassword = _enc.GetString(encodedUsernamePassword).Split(new char[1] { ':' }, 2, StringSplitOptions.None); // Lookup the user. user = ActiveDirectory.FindUser(usernamePassword[0], Options.GroupType); // If the user is not null, we found a match. if (user != null) { // Attempt to validate the given credentials. if ((authenticationResponse = ActiveDirectory.Authenticate(Options.Domain, usernamePassword[0], usernamePassword[1])) == AccountAuthenticationResponse.Success) { // Get a ClaimsIdentity based on this UserPrincipal. ClaimsIdentity userCI = ActiveDirectory.GetUserClaimsIdentity(user.Value); // Return successfully. return(Task.FromResult(AuthenticateResult.Success(new AuthenticationTicket(new ClaimsPrincipal(userCI), new AuthenticationProperties(), this.Scheme.Name)))); } } } // If we got down this far, we were not authorized for one reason or another. // This could mean one of the following: not found, expired, disabled, locked out, bad username or password. // You can check the user or authenticationResponse variables to see what happened. return(Task.FromResult(AuthenticateResult.Fail("Invalid credentials."))); }
private UserInfo?AuthenticateUser(UserInfo login) { UserInfo?user = null; if (string.IsNullOrWhiteSpace(login.Password)) { return(user); } using (var context = new ManageDataContext()) { var result = context.UserInfos.Where(w => w.UserName.ToLower() == login.UserName.ToLower()).FirstOrDefault(); if (result != null) { if (PasswordStorage.VerifyPassword(login.Password, result.PasswordHash !)) { user = result; } } } return(user); }
// Schedule the job public Unlocker() { UserInfo?userInfo = GetUserInfo(); if (!userInfo.HasValue) { m_Result[0] = new UnlockResult { Value = UnlockResult.Status.NoUser }; return; } var authInfo = new AuthInfo(userInfo.Value); if (UnityEngine.PlayerPrefs.HasKey("Havok.Auth.Token") && UnityEngine.PlayerPrefs.HasKey("Havok.Auth.TokenExpiry")) { try { authInfo.HavokToken = Convert.ToUInt64(UnityEngine.PlayerPrefs.GetString("Havok.Auth.Token")); authInfo.HavokTokenExpiry = Convert.ToInt64(UnityEngine.PlayerPrefs.GetString("Havok.Auth.TokenExpiry")); authInfo.HavokSubscriptionExpiry = Convert.ToInt64(UnityEngine.PlayerPrefs.GetString("Havok.Auth.SubscriptionExpiry")); } catch (FormatException) { // The saved prefs don't match what we expect, just ignore them } } m_AuthInfo[0] = authInfo; m_Result[0] = new UnlockResult { Value = UnlockResult.Status.Invalid }; m_jobHandle = new UnlockJob() { AuthInfo = m_AuthInfo, Result = m_Result }.Schedule(); }
public static void AddAndCommitNewRepositoryFiles(string repositoryDirectory, UserInfo?user = null) => AddFiles(repositoryDirectory, user ?? CDorst);
public static void AddAndCommitGitAttributeIgnoreFiles(string repositoryDirectory, UserInfo?user = null) { SaveGitAttributeIgnoreFiles(repositoryDirectory); AddAndCommitChanges(repositoryDirectory, CommitMessage, user); }
public void InitiateUserSpawning(UserInfo userInfo) { _userInfo = userInfo; }
public async Task ProcessAsync(MessageContext context, HttpApiClient api) { DateTimeOffset now = DateTimeOffset.UtcNow; DateTimeOffset start = now.AddYears(-1); int? osuId = await _dataProvider.GetOsuIdAsync(context.UserId).ConfigureAwait(false); if (osuId == null) { _ = await api.SendMessageAsync(context.Endpoint, "未绑定").ConfigureAwait(false); return; } UserSnapshot?snap = await _newbieContext.UserSnapshots .Where(s => s.UserId == osuId && s.Mode == _mode && s.Date > start) .OrderBy(s => s.Date) .FirstOrDefaultAsync().ConfigureAwait(false); if (snap is null) { _ = await api.SendMessageAsync(context.Endpoint, "没有找到数据").ConfigureAwait(false); return; } UserInfo?userInfo = await _osuApiClient.GetUser(osuId.Value, _mode).ConfigureAwait(false); if (userInfo is null) { userInfo = (await _newbieContext.UserSnapshots .Where(s => s.UserId == osuId && s.Mode == _mode) .OrderByDescending(s => s.Date) .FirstAsync().ConfigureAwait(false)).UserInfo; } int startPC = snap.UserInfo.PlayCount; int currentPC = userInfo.PlayCount; List <UserPlayRecord> playList = await _newbieContext.UserPlayRecords .Where(r => r.UserId == osuId && r.Mode == _mode && r.PlayNumber > startPC) .OrderBy(r => r.PlayNumber) .ToListAsync().ConfigureAwait(false); _ = await api.SendMessageAsync(context.Endpoint, $"数据完整度:{playList.Count} of {currentPC - startPC}。功能制作中。").ConfigureAwait(false); if (playList.Count == 0) { return; } // assign data to fields. _userPlayRecords = playList; { // days played (int days, int totalDays) = GetPlayedDays(); _ = await api.SendMessageAsync(context.Endpoint, $"你在过去一年中有 {days} 天打了图。").ConfigureAwait(false); } { // most played (int bid, int count, BeatmapInfo? beatmap) = await GetMostPlayedBeatmapAsync().ConfigureAwait(false); _ = await api.SendMessageAsync(context.Endpoint, $"你最常打的一张图是 {bid},打了 {count} 次。" + $"{beatmap}").ConfigureAwait(false); } { // most playing hour var mostPlayingHour = GetMostPlayingHours(); _ = await api.SendMessageAsync(context.Endpoint, $"你最常在 {mostPlayingHour}-{mostPlayingHour + 1} 时打图。").ConfigureAwait(false); } }
public static async Task CreateRepository(string directory, string name, string description, BasicAuthenticationCredentials credentials = null, UserInfo?user = null) { await Create(name, description, credentials); InitializeRepository(directory, RemoteUri(name, credentials), user); }
/// <summary> /// Возвращает текущее время для юзера в спец формате /// </summary> private string GetTime(UserInfo?user) { var timeZone = user?.TimeZoneId ?? Constants.DefaultTimeZoneId; return(TimeHelper.ToClientTime(timeZone, _dateTimeService.GetCurrentTimeUtc()).ToString("dd.MM.yy-HH.mm")); }
private string GetArchiveName(UserInfo?user, string baseName, string suffix) { return($"{Clean(baseName)}.{suffix}.{GetTime(user)}.zip"); }
VisualElement CreateVenueUi(TokenAuthWidget tokenAuth, VisualElement tokenAuthView, UserInfo?userInfo) { var container = new VisualElement() { style = { flexDirection = FlexDirection.Row, flexGrow = 1, } }; var sidePane = new VisualElement() { style = { borderColor = new StyleColor(Color.gray), borderRightWidth = 1, width = 250, } }; sidePane.EnableInClassList("pane", true); var mainPane = new VisualElement() { style = { flexGrow = 1 } }; mainPane.EnableInClassList("pane", true); container.Add(sidePane); container.Add(mainPane); // Side sidePane.Add(tokenAuthView); if (userInfo.HasValue) { var sideMenu = new SideMenuVenueList(userInfo.Value); sideMenu.AddView(sidePane); ReactiveBinder.Bind(sideMenu.reactiveForceLogout, forceLogout => { if (forceLogout) { tokenAuth.Logout(); } }); // Main ReactiveBinder.Bind(sideMenu.reactiveCurrentVenue, currentVenue => { mainPane.Clear(); if (currentVenue != null) { var venueContent = new ScrollView(ScrollViewMode.Vertical) { style = { flexGrow = 1 } }; new EditAndUploadVenueView(userInfo.Value, currentVenue, () => { sideMenu.RefetchVenueWithoutChangingSelection(); }).AddView(venueContent); mainPane.Add(venueContent); } }); } else { mainPane.Clear(); } return(container); }
public UseCase_AddProductToCart_TestLogic(SystemContext systemContext, UserInfo?userInfo) : base(systemContext) { UserInfo = userInfo; }
public static void AddAndCommitLicense(string repositoryDirectory, UserInfo?user = null) { SaveGnuGpl3License(repositoryDirectory); AddAndCommitChanges(repositoryDirectory, CommitMessage, user); }
public static async Task CloneOrCreate(string directory, string name, string description, BasicAuthenticationCredentials credentials = null, UserInfo?user = null) { credentials = credentials ?? CDorst; var repository = new AccountRepository(credentials.User, name); Clear(directory); if (await Exists(repository)) { Clone(directory, RemoteUri(repository).ToString()); } else { await CreateRepository(directory, name, description, credentials, user); } }
public static void AddAndCommitAppveyorYml(string repositoryDirectory, UserInfo?user = null) { SaveAppveyorYml(repositoryDirectory); AddAndCommitChanges(repositoryDirectory, CommitMessage, user); }
public static void InitializeRepository(string directory, Uri remote, UserInfo?user = null) { Init(directory); AddAndCommitNewRepositoryFiles(directory, user); AddRemoteAndPush(directory, remote); }
internal User(UserInfo info) : this(info.Number) { _info = info; }