public void LogIn(object o, EventArgs e) { string email = emailEdit.Text; string password = passwordEdit.Text; bool stayLoggedIn = stayLoggedInCheckBox.Checked; VFIDHolder.Value = RequestSender.Login(email, password, false); if (VFIDHolder.Value > 0) { int id = RequestSender.GetLoggedInAccountId(); Account acc = new Account { Permissions = RequestSender.GetAccountPermissions(id) }; if (acc.Can((uint)Permissions.VIEW_ACCOUNTS)) { MainActivity.CanViewAccounts = true; } MainActivity.IsLoggedIn = true; // Save credentials if (stayLoggedIn) { Xamarin.Essentials.Preferences.Set("saved_email", email); Xamarin.Essentials.Preferences.Set("saved_password", Hasher.Hash(password)); } else { Xamarin.Essentials.Preferences.Set("saved_email", ""); Xamarin.Essentials.Preferences.Set("saved_password", ""); } MainActivity.CanViewAccounts = RequestSender.ThisAccount().Can((uint)Permissions.VIEW_ACCOUNTS); Toast.MakeText(this, "Logged in", ToastLength.Short).Show(); Finish(); return; } MainActivity.IsLoggedIn = false; Toast.MakeText(this, "Invalid credentials", ToastLength.Short).Show(); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); mainPanel = FindViewById <CoordinatorLayout>(Resource.Id.mainPanel); fabMain = FindViewById <FloatingActionButton>(Resource.Id.fab_main); fabEvents = FindViewById <FloatingActionButton>(Resource.Id.fab_events); fabAccount = FindViewById <FloatingActionButton>(Resource.Id.fab_account_manager); fabSettings = FindViewById <FloatingActionButton>(Resource.Id.fab_settings); fabLogin = FindViewById <FloatingActionButton>(Resource.Id.fab_login); bgFabMenu = FindViewById <View>(Resource.Id.bg_fab_menu); bottomSheet = FindViewById <RelativeLayout>(Resource.Id.bottom_sheet); sportSpinner = FindViewById <Spinner>(Resource.Id.sportSpinner); searchDates = FindViewById <EditText>(Resource.Id.searchDate); searchButton = FindViewById <Button>(Resource.Id.searchButton); eventPin = Bitmap.CreateScaledBitmap(BitmapFactory.DecodeResource(Resources, Resource.Drawable.BasePin), 84, 124, true); eventList = FindViewById <RecyclerView>(Resource.Id.PulloutEventView); SetUpBottomSheet(210); SetUpMap(); fabMain.Click += (o, e) => { if (!isFabOpen) { ShowFabMenu(); } else { CloseFabMenu(); } }; bgFabMenu.Click += (o, e) => CloseFabMenu(); fabEvents.Click += (o, e) => GoToActivity(typeof(EventManagerActivity)); fabSettings.Click += (o, e) => { Intent intent = new Intent(this, typeof(SettingsActivity)); StartActivityForResult(intent, 1); }; fabAccount.Click += (o, e) => GoToActivity(typeof(AdminPanelActivity)); fabLogin.Click += (o, e) => LogIn(); var visibility = ViewStates.Visible; Console.WriteLine(visibility == ViewStates.Visible); // Try auto login string email = Xamarin.Essentials.Preferences.Get("saved_email", ""); string passwordHash = Xamarin.Essentials.Preferences.Get("saved_password", ""); if (email != "" || passwordHash != "") { if (email != "" && passwordHash != "") { VFIDHolder.Value = RequestSender.Login(email, passwordHash); if (VFIDHolder.Value > 0) { int id = RequestSender.GetLoggedInAccountId(); Account acc = new Account { Permissions = RequestSender.GetAccountPermissions(id) }; if (acc.Can((uint)Permissions.VIEW_ACCOUNTS)) { CanViewAccounts = true; } IsLoggedIn = true; Toast.MakeText(this, "Logged in", ToastLength.Long).Show(); } else { Toast.MakeText(this, "Auto sign in failed", ToastLength.Long).Show(); } } else { Toast.MakeText(this, "Auto sign in failed", ToastLength.Long).Show(); } } else { Xamarin.Essentials.Preferences.Set("saved_email", ""); Xamarin.Essentials.Preferences.Set("saved_password", ""); } AskForLocationAsync(); }