Esempio n. 1
0
        async Task ExecuteLoadItemsCommand()
        {
            IsBusy = true;
            if (!SecureStorageHelper.CheckIfUserSessionIsActive().Result)
            {
                App.Current.MainPage = new NavigationPage(new LoginPage());
            }

            try
            {
                Items.Clear();
                var items = await DataStore.GetSharedItems(true);

                foreach (var item in items)
                {
                    Items.Add(item);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
Esempio n. 2
0
        private async void OnSendTokenClicked(object obj)
        {
            if (SecureStorageHelper.CheckIfUserSessionIsActive().Result)
            {
                App.Current.MainPage = new NavigationPage(new ItemsPage());
            }
            if (string.IsNullOrEmpty(Token))
            {
                MessagingCenter.Send(this, "AuthError", "Token cannot be empty.");
                return;
            }


            IsBusy = true;

            ApiTwoFactorResponse apiResponse = await _apiService.TwoFactorLogIn(await SecureStorageHelper.GetUserId(), Token);

            IsBusy = false;

            if (apiResponse.VerificationStatus != 1)
            {
                if (apiResponse.VerificationStatus == 0)
                {
                    MessagingCenter.Send(this, "AuthError", apiResponse.Messages.First());
                    return;
                }
                else
                {
                    MessagingCenter.Send(this, "AuthError", "Your code has expired. Try log in again.");
                    SecureStorageHelper.ClearData();
                    await App.Current.MainPage.Navigation.PopModalAsync();

                    return;
                }
            }

            IsBusy = true;
            if (!_jwtHelper.ValidateToken(apiResponse.AccessToken, out _))
            {
                // indicate errors
                MessagingCenter.Send(this, "AuthError", "Json web token is invalid");
                await App.Current.MainPage.Navigation.PopModalAsync();

                return;
            }


            await SecureStorageHelper.SaveUserData(apiResponse);



            //App.Current.MainPage.Navigation.InsertPageBefore(new ItemsPage(), TwoFactorPage);
            // await Navigation.PopAsync();

            await App.Current.MainPage.Navigation.PopModalAsync();

            IsBusy = false;
            App.Current.MainPage = new NavigationPage(new ItemsPage());
        }
Esempio n. 3
0
        // Creates mainUser and goes to convo screen
        void signInToServerResponse(object sender, EventArgs e)
        {
            int messageIndex = serverConnection.unreadMessages.Count - 1;

            if (messageIndex < 0)
            {
                return;
            }
            JObject message = JObject.Parse(serverConnection.unreadMessages[messageIndex]);
            string  type    = serverConnection.interpretMessageType(message);

            if (type == "signedIn")
            {
                User newUser = new User();
                newUser.username = message[type]["username"].ToString();
                newUser.email    = message[type]["email"].ToString();
                newUser.user_id  = message[type]["id"].ToString();
                newUser.pubKey   = message[type]["pubKey"].ToString();

                // Load storage. If not same user, reset
                loadChatsAndUsersFromStorage();
                if (mainUser == null || newUser.user_id != mainUser.user_id)
                {
                    // Deletes all storage
                    SecureStorageHelper ssHelper = new SecureStorageHelper();
                    ssHelper.RemoveAllItems();

                    // Loads new users and resets memory of users&chats
                    mainUser          = newUser;
                    otherUsers        = new Dictionary <string, User> {
                    };                                             // username:user
                    usernameIdMatches = new Dictionary <string, string> {
                    };                                             //user_id:username
                    myChats           = new Dictionary <string, Chat> {
                    };                                             // chatname:chat
                    chatNameMatches   = new Dictionary <string, string> {
                    };                                             // chat_id:chatname

                    // Creates a new public key and updates server
                    AsymmetricKeyHelper akh = new AsymmetricKeyHelper(myAsymKeyPairAlias + mainUser.username);
                    akh.CreateKey();
                    string pubKey = akh.GetSharablePublicKey();
                    updatePubKey(pubKey);
                }


                // Post sign-in activities
                getAllUsers();
                getMyChats();
            }

            if (type == "noAccount")
            {
                RunOnUiThread(() =>
                {
                    createAccountScreen();
                });
            }
        }
Esempio n. 4
0
        public async Task <IEnumerable <SharedLoginModel> > GetSharedItems(bool forceRefresh = false)
        {
            // return await Task.FromResult(items);

            var sharedLogins = _apiService.GetSharedLogins(SecureStorageHelper.GetUserId().Result.ToString()).ToList();

            return(await Task.FromResult(sharedLogins));
        }
Esempio n. 5
0
        void loadChatsAndUsersFromStorage()
        {
            SecureStorageHelper storageHelper = new SecureStorageHelper();

            myChats         = storageHelper.GetItem <Dictionary <string, Chat> >("myChats");
            chatNameMatches = storageHelper.GetItem <Dictionary <string, string> >("chatNameMatches");
            mainUser        = storageHelper.GetItem <User>("mainUser");
        }
Esempio n. 6
0
        private async void OnShare()
        {
            if (!(ReceiverEmail.Contains("@") && ReceiverEmail.Contains(".")))
            {
                EmailError = "Please enter valid email!";
                return;
            }


            var      startDate = DateTime.UtcNow.ToLocalTime();
            DateTime endDate;

            try
            {
                endDate = DateTime.Parse(GetExpireDate());
            }
            catch (FormatException)
            {
                ExpireDateResult = "Date format is invalid";
                return;
            }

            if (startDate >= endDate)
            {
                ExpireDateResult = "Start date is later than expire date!";
                return;
            }
            IsBusy = true;
            var loginDataToShare = await DataStore.GetItemAsync(ItemId);

            var password = EncService.Decrypt(SecureStorageHelper.GetUserKey().Result,
                                              loginDataToShare.Password);
            LoginData newLoginData = new LoginData()
            {
                Name     = loginDataToShare.Name + " From " + SecureStorageHelper.GetUserEmail(),
                Login    = loginDataToShare.Login,
                Password = EncService.Encrypt(App.AppSettings.SecretEncryptionKey, password),
                Website  = loginDataToShare.Website,
                Email    = loginDataToShare.Email ?? "Not added"
            };
            var model = new ShareLoginModel
            {
                LoginData     = newLoginData,
                ReceiverEmail = ReceiverEmail,
                StartDate     = startDate,
                EndDate       = endDate
            };
            var apiResponse = await _apiService.HandleLoginShare(model);

            IsBusy = false;
            if (!apiResponse.Success)
            {
                MessagingCenter.Send(this, "ShareNotify", apiResponse.Messages.First());
                return;
            }
            MessagingCenter.Send(this, "ShareNotify", apiResponse.Messages.First());
            await App.Current.MainPage.Navigation.PopModalAsync();
        }
Esempio n. 7
0
        void saveChatsAndUsersToStorage()
        {
            SecureStorageHelper storageHelper = new SecureStorageHelper();

            storageHelper.StoreItem <Dictionary <string, Chat> >("myChats", myChats);
            storageHelper.StoreItem <Dictionary <string, string> >("chatNameMatches", chatNameMatches);
            storageHelper.StoreItem <User>("mainUser", mainUser);
            // Not saving users incase pubkey is updated.
        }
Esempio n. 8
0
        public WebDataStore()
        {
            _apiService = new ApiService();
            var tempItems = _apiService.GetAllUserData <LoginData>(SecureStorageHelper.GetUserId().Result).Result;

            if (!(tempItems is null))
            {
                items = tempItems.ToList();
            }
        }
        protected override Task NavigateToFirstViewModel(object hint = null)
        {
            bool isLogined = SecureStorageHelper.GetBoolean(Constants.IsLogined, false);

            if (isLogined)
            {
                return(NavigationService.Navigate <DashboardViewModel>());
            }
            return(NavigationService.Navigate <LoginViewModel>());
        }
Esempio n. 10
0
        public async Task <IEnumerable <LoginData> > GetItemsAsync(bool forceRefresh = false)
        {
            var tempItems = _apiService.GetAllUserData <LoginData>(SecureStorageHelper.GetUserId().Result).Result;

            if (!(tempItems is null))
            {
                items = tempItems.ToList();
            }

            return(await Task.FromResult(items));
        }
        public override async Task Initialize()
        {
            await base.Initialize();

            OrganizationName = SecureStorageHelper.GetString(Constants.OranizationName);

            List <TaskModelEntity> taskEntities = await _taskRepository.GetAllTasksList(SecureStorageHelper.GetString(Constants.CurrentUserId));

            var tasks = _mapper.Map <List <TaskModelEntity>, List <TaskModelResult> >(taskEntities);

            foreach (var section in AllSectionItems)
            {
                section.TaskItems = new ObservableCollection <TaskModelResult>(tasks.Where(x => x.TaskStatus == section.CurrentSectionStatus).ToList());
            }
        }
Esempio n. 12
0
        public App()
        {
            InitializeComponent();

            DependencyService.Register <WebDataStore>();
            DependencyService.Register <EncryptionService>();


            if (SecureStorageHelper.CheckIfUserSessionIsActive().Result)
            {
                MainPage = new NavigationPage(new ItemsPage());
            }
            else
            {
                MainPage = new NavigationPage(new LoginPage());
            }
        }
Esempio n. 13
0
        private async void OnSave()
        {
            IsBusy = true;
            LoginData newLoginData = new LoginData()
            {
                Id       = Int32.Parse(Id),
                Name     = Name,
                Login    = Login,
                Password = EncService.Encrypt(SecureStorageHelper.GetUserKey().Result, Password),
                Website  = Website,
                Email    = Email ?? "Not added",
                UserId   = SecureStorageHelper.GetUserId().Result
            };

            await DataStore.UpdateItemAsync(newLoginData);

            IsBusy = false;
            // This will pop the current page off the navigation stack
            await App.Current.MainPage.Navigation.PopModalAsync();
        }
Esempio n. 14
0
 void Handle_Clicked(object sender, System.EventArgs e)
 {
     SecureStorageHelper.ClearData();
     App.Current.MainPage = new NavigationPage(new LoginPage());
 }
 public Task SaveAsync(IEnumerable <Subscription> subscriptions)
 {
     return(SecureStorageHelper.SetObjectAsync(SubscriptionsKey, subscriptions));
 }
 public Task <IEnumerable <Subscription> > GetAsync()
 {
     return(SecureStorageHelper.GetObjectAsync <IEnumerable <Subscription> >(SubscriptionsKey));
 }