/// <summary> /// Get Report /// </summary> /// <param name="ReportId"></param> /// <returns></returns> public TokenLite Get(string email) { string encryptEmail = VikingCommonHelper.VikingEncodeData.Encrypt(email, true, CommonConstant.DefaultSecureKey); var query = from c in _connection.Table <TokenLite>() where c.UserId.Equals(encryptEmail) select c; TokenLite tokenLite = query.FirstOrDefault(); return(tokenLite); }
public TokenLite GetLastLogin() { var query = from c in _connection.Table <TokenLite>() orderby c.Id descending select c; TokenLite tokenLite = query.FirstOrDefault(); if (tokenLite != null) { string email = tokenLite.UserId; tokenLite.UserId = VikingCommonHelper.VikingEncodeData.Decrypt(email, true, CommonConstant.DefaultSecureKey); } return(tokenLite); }
/// <summary> /// Create Report /// </summary> /// <param name="TokenLite"></param> public void Create(TokenLite TokenLite) { _connection.Insert(TokenLite); _connection.Commit(); }
/// <summary> /// Delete Report /// </summary> /// <param name="TokenLite"></param> public void Delete(TokenLite TokenLite) { _connection.Delete(TokenLite); _connection.Commit(); }
async void Login_Clicked(object sender, EventArgs e) { App.localizer.SetLocale(App.defaultCulture); Loading.IsVisible = true; Loading.IsRunning = true; if (App.user == null || string.IsNullOrEmpty(App.user.UserId)) { if (App.IsConnectivity) { var result = await App.AuthenticationClient.AcquireTokenAsync( Constants.Scopes, string.Empty, UiOptions.SelectAccount, string.Empty, null, Constants.Authority, Constants.SignUpSignInPolicy); if (result != null) { try { var jwt = new JwtSecurityToken(result.IdToken); string email = jwt.Claims.First(c => c.Type == "emails").Value; RestClient restClient = App.restClient; string json = await restClient.GetAndReturnObject("users", email, null); //App.userId = email; Models.User users = await restClient.Get <Models.User>("users/" + email + "/location"); if (users == null) { users = new Models.User(); } App.user = users; TokenAuth tokenAuth = new TokenAuth(); tokenAuth.userId = users != null ? users.UserId : null; tokenAuth.secretCode = App.user.SecretCode; App.tokenAuth = tokenAuth; App.token = await RestClient.PostAndReturnToken <Token>("tokens", tokenAuth); App.ListContact = await restClient.Get <List <Models.User> >("users"); #region Sao luu du lieu cuc bo var repository = App.Get <UserRepository>(); //Luu nguoi dung cuc bo TokenRepository tokenRepository = App.Get <TokenRepository>(); TokenLite tokenLite = new TokenLite(); tokenLite.UserId = VikingCommonHelper.VikingEncodeData.Encrypt(email, true, CommonConstant.DefaultSecureKey); tokenRepository.Create(tokenLite); var UserLites = repository.GetAll(); var ListTemp = App.ListContact.Where(x => !UserLites.Select(y => y.UserId).Contains(x.UserId)).ToList(); if (ListTemp != null && ListTemp.Any()) { UserLites = ListTemp.ConvertToListUserLite(); foreach (var item in UserLites) { repository.Create(item); } } #endregion App.ChangeLanguage(); } catch (Exception ex) { } await DisplayAlert(App.localizeResProvider.GetText("Notification"), App.localizeResProvider.GetText("LoginSuccess"), "Ok"); } } } else { App.AuthenticationClient.UserTokenCache.Clear(Constants.ApplicationID); App.user = null; App.token = null; App.tokenAuth = null; //App.userId = ""; App.ChangeLanguage(); await DisplayAlert(App.localizeResProvider.GetText("Notification"), App.localizeResProvider.GetText("LogoutSuccess"), "Ok"); } Loading.IsVisible = false; Loading.IsRunning = false; }