public void Login() { //TODO: Try to update this attribute with a broadcast message try { LoginController.tokenModel = CredentialsService.GetTokenModel(); LoginController.userModel = new PortableLibrary.Business.LoginManager().GetUserByTokenSync(CredentialsService.access_token); if (LoginController.userModel != null) { var menuController = this.Window.RootViewController.Storyboard.InstantiateViewController("MenuNavController"); if (menuController != null) { this.Window.RootViewController = menuController; } } else { ResetCredentials(); } } catch (System.Exception ex) { Utils.HandleException(ex); } }
public override void WillEnterForeground(UIApplication application) { // Called as part of the transiton from background to active state. // Here you can undo many of the changes made on entering the background. if (CredentialsService.DoCredentialsExist() && !CredentialsService.GetTokenModel().isStillValid(System.DateTime.Now)) { ResetCredentials(); } }
private void LogoutBtn_TouchUpInside(object sender, EventArgs e) { CredentialsService.DeleteCredentials(); LoginController.tokenModel = null; LoginController.userModel = null; var loginController = this.Storyboard.InstantiateViewController("LoginNavController"); if (loginController != null) { this.PresentViewController(loginController, true, null); } }
private void ResetCredentials() { CredentialsService.DeleteCredentials(); LoginController.tokenModel = null; LoginController.userModel = null; var loginController = this.Window.RootViewController.Storyboard.InstantiateViewController("LoginNavController") as LoginController; if (loginController != null) { this.Window.RootViewController = loginController; } }
private async void FinishAuthentication(NSNotification notification) { sfViewController.DismissViewController(true, null); try { string url = notification.Object.ToString(); if (url.Contains("access_token")) { BTProgressHUD.Show("Checking your credentials...", -1, ProgressHUD.MaskType.Clear); string accessToken = url.Split('#')[1].Split('=')[1].Split('&')[0]; string tokenType = url.Split('=')[2].Split('&')[0]; string expiresIn = url.Split('=')[3]; Console.WriteLine("Access Token = " + accessToken); userModel = await loginManager.GetUserById(accessToken); if (tokenModel == null) { tokenModel = new TokenModel(); tokenModel.access_token = accessToken; tokenModel.userName = userModel.userName; tokenModel.expires_in = Int32.Parse(expiresIn); tokenModel.token_type = tokenType; tokenModel.expires = DateTime.Now.AddSeconds(tokenModel.expires_in); } CredentialsService.SaveCredentials(tokenModel, userModel); Console.WriteLine("User = "******"User Logged!"); } if (url.Contains("#error=access_denied")) { BTProgressHUD.Dismiss(); } } catch (Exception ex) { BTProgressHUD.Dismiss(); Utils.HandleException(ex); } }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException; TaskScheduler.UnobservedTaskException += TaskSchedulerOnUnobservedTaskException; // Override point for customization after application launch. // If not required for your application you can safely delete this method string userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 8_2 like Mac OS X) AppleWebKit/600.1.4 (KHTML, like Gecko) Mobile/12D508 [FBAN/FBIOS;FBAV/27.0.0.10.12;FBBV/8291884;FBDV/iPhone7,1;FBMD/iPhone;FBSN/iPhone OS;FBSV/8.2;FBSS/3; FBCR/vodafoneIE;FBID/phone;FBLC/en_US;FBOP/5]"; // set default useragent NSDictionary dictionary = NSDictionary.FromObjectAndKey(NSObject.FromObject(userAgent), NSObject.FromObject("UserAgent")); NSUserDefaults.StandardUserDefaults.RegisterDefaults(dictionary); ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true; SDWebImageManager.SharedManager.ImageCache.ClearMemory(); SDWebImageManager.SharedManager.ImageCache.ClearDisk(); if (CredentialsService.DoCredentialsExist()) { if (!CredentialsService.GetTokenModel().isStillValid(System.DateTime.Now)) { CredentialsService.DeleteCredentials(); } else { Login(); } } //Loading View config ProgressHUD.Shared.HudBackgroundColour = UIColor.FromWhiteAlpha(0.0f, 0.8f); ProgressHUD.Shared.HudForegroundColor = UIColor.White; ProgressHUD.Shared.Ring.BackgroundColor = UIColor.FromWhiteAlpha(0.0f, 0.8f); ProgressHUD.Shared.Ring.Color = UIColor.White; return(true); }
async partial void btnEnter_TouchUpInside(UIKit.UIButton sender) { BTProgressHUD.Show("Checking your credentials...", -1, ProgressHUD.MaskType.Clear); if (string.Empty.Equals(txtUsername.Text)) { BTProgressHUD.Dismiss(); UIAlertView alert = new UIAlertView() { Title = "E-mail", Message = "Please fill in the E-mail" }; alert.AddButton("OK"); alert.Show(); } else if (string.Empty.Equals(txtPassword.Text)) { BTProgressHUD.Dismiss(); var alert = UIAlertController.Create("Password", "Please fill in the Password", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else { try { UserLoginModel userLoginModel = new UserLoginModel(txtUsername.Text, txtPassword.Text); tokenModel = await loginManager.GetAuthorizationToken(userLoginModel); userModel = await loginManager.GetUserById(tokenModel.access_token); CredentialsService.SaveCredentials(tokenModel, userModel); Login(); } catch (Exception ex) { if (ex.Message.Equals("901")) { var alert = UIAlertController.Create("Login", "The user name or password is incorrect.", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if (ex.Message.Equals("903")) { var alert = UIAlertController.Create("Login", "An error occurred while sending the e-mail confirmation.", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if (ex.Message.Equals("905")) { var alert = UIAlertController.Create("Login", "The user e-mail is not confirmed. A new e-mail confirmation has been sent to user.", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else { Utils.HandleException(ex); } BTProgressHUD.Dismiss(); } } }
public override void ViewDidLoad() { base.ViewDidLoad(); this.RestrictRotation(UIInterfaceOrientationMask.Portrait); txtName.TextColor = UIColor.FromRGB(90, 89, 89); txtEmail.TextColor = UIColor.FromRGB(90, 89, 89); txtPassword.TextColor = UIColor.FromRGB(90, 89, 89); txtConfirmPassword.TextColor = UIColor.FromRGB(90, 89, 89); NSMutableAttributedString terms = new NSMutableAttributedString("I agree with Askker terms and conditions and privacy policy"); var linkRange = terms.MutableString.LocalizedStandardRangeOfString(new NSString("Askker terms")); terms.AddAttribute(UIStringAttributeKey.ForegroundColor, UIColor.Blue, linkRange); termsText.AttributedText = terms; var gAgree = new UITapGestureRecognizer(); gAgree.AddTarget(() => PresentViewControllerAsync(new SFSafariViewController(new NSUrl("https://askker.io/privacy-policy.html")), true)); termsText.AddGestureRecognizer(gAgree); termsText.UserInteractionEnabled = true; UINavigationBar.Appearance.TitleTextAttributes = new UIStringAttributes { ForegroundColor = UIColor.FromRGB(90, 89, 89) }; // Keyboard dispose when clicking outside the comment box var g = new UITapGestureRecognizer { CancelsTouchesInView = false }; g.AddTarget(() => View.EndEditing(true)); View.AddGestureRecognizer(g); btnRegister.TouchUpInside += async(sender, e) => { if ("".Equals(txtName.Text)) { var alert = UIAlertController.Create("Name", "Please fill in the Name", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if ("".Equals(txtEmail.Text)) { var alert = UIAlertController.Create("E-Mail", "Please fill in the E-Mail", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if ("".Equals(txtPassword.Text)) { var alert = UIAlertController.Create("Password", "Please fill in the Password", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if ("".Equals(txtConfirmPassword.Text)) { var alert = UIAlertController.Create("Confirm Password", "Please confirm the Password", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if (!txtConfirmPassword.Text.Any(c => char.IsUpper(c))) { var alert = UIAlertController.Create("Confirm Password", "Password must have at least one uppercase", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if (!txtConfirmPassword.Text.Any(c => char.IsDigit(c))) { var alert = UIAlertController.Create("Confirm Password", "Password must have at least one number", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if (!txtPassword.Text.Equals(txtConfirmPassword.Text)) { var alert = UIAlertController.Create("Confirm Password", "Password and Confirm Password must match", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else if (swAgree.On == false) { var alert = UIAlertController.Create("Policy Agreement", "Please accept the policy", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else { try { BTProgressHUD.Show("Registering...", -1, ProgressHUD.MaskType.Clear); RegisterManager registerManager = new RegisterManager(); UserRegisterModel userRegisterModel = new UserRegisterModel(txtName.Text, txtEmail.Text, txtPassword.Text, txtConfirmPassword.Text, swAgree.On); await registerManager.RegisterUser(userRegisterModel); LoginManager loginManager = new LoginManager(); UserLoginModel userLoginModel = new UserLoginModel(txtEmail.Text, txtPassword.Text); LoginController.tokenModel = await loginManager.GetAuthorizationToken(userLoginModel); LoginController.userModel = await loginManager.GetUserById(LoginController.tokenModel.access_token); CredentialsService.SaveCredentials(LoginController.tokenModel, LoginController.userModel); var menuController = this.Storyboard.InstantiateViewController("MenuNavController"); if (menuController != null) { this.PresentViewController(menuController, true, null); } BTProgressHUD.Dismiss(); } catch (Exception ex) { BTProgressHUD.Dismiss(); if (ex.Message.Equals("902")) { var alert = UIAlertController.Create("Register", "E-mail already registered", UIAlertControllerStyle.Alert); alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); PresentViewController(alert, true, null); } else { Utils.HandleException(ex); } } } }; }
public static void HandleException(Exception ex) { if (ex.Message.Equals("Unauthorized")) { if (CredentialsService.DoCredentialsExist()) { CredentialsService.DeleteCredentials(); } if (UIApplication.SharedApplication.KeyWindow != null && UIApplication.SharedApplication.KeyWindow.RootViewController.GetType() != typeof(LoginController)) { UIStoryboard Storyboard = UIStoryboard.FromName("Main", null); var initialController = Storyboard.InstantiateInitialViewController() as UIViewController; if (initialController != null) { UIApplication.SharedApplication.KeyWindow.RootViewController = initialController; } ShowToast("Your session has expired. Please login again.", 3000); } else { var alert = new UIAlertView { Title = "Session expired", Message = "Your session has expired. Please login again." }; alert.AddButton("OK"); alert.Show(); } } else { var errorCodes = new Dictionary <string, string> { { "900", "Sorry, but some unexpected error happened" }, { "901", "Incorrect user and/or password, please try again" }, { "902", "Your email address has already been registered, try to login" }, { "903", "Sorry, an unexpected error happened, please try again later" }, { "904", "Sorry, an unexpected error happened, please try again later" }, { "905", "Your registration has not yet been confirmed, we will send the confirmation link to your email" }, { "906", "Email not registered, please register" }, { "907", "Sorry, an unexpected error happened, please try again later" }, { "908", "We have received your contact email, thank you!" }, { "909", "Email already registered by Facebook. Please try to login with Facebook" }, { "910", "Email already registered by Google. Please try to login with Google" }, { "911", "Email already registered. Please try to login or recover your password" }, }; string message; if (errorCodes.ContainsKey(ex.Message)) { message = errorCodes[ex.Message]; } else { message = ex.Message; } //if (UIApplication.SharedApplication.KeyWindow != null) //{ // ShowToast(message, 3000); //} //else //{ var alert = new UIAlertView { Title = "Something went wrong", Message = message }; alert.AddButton("OK"); alert.Show(); //} } }
public override void ViewDidLoad() { base.ViewDidLoad(); updateProfilePictureObserver = NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UpdateProfilePicture"), UpdateProfilePicture); updateUserNameObserver = NSNotificationCenter.DefaultCenter.AddObserver(new NSString("UpdateUserName"), UpdateUserName); View.BackgroundColor = UIColor.FromRGB(33, 33, 33); var scrollView = new UIScrollView(new RectangleF(0, 0, (float)View.Frame.Width, (float)View.Frame.Height)); profileImageView = new UIImageView(new RectangleF(85, 20, 90, 90)); profileImageView.ContentMode = UIViewContentMode.ScaleAspectFill; profileImageView.Image = UIImage.FromBundle("Profile"); profileImageView.Layer.CornerRadius = (profileImageView.Frame.Width / 2); profileImageView.Layer.MasksToBounds = true; var tapGestureRecognizer = new UITapGestureRecognizer(this, new ObjCRuntime.Selector("TapProfilePictureSelector:")); profileImageView.AddGestureRecognizer(tapGestureRecognizer); profileImageView.UserInteractionEnabled = true; if (LoginController.userModel.profilePicturePath != null) { Utils.SetImageFromNSUrlSession(LoginController.userModel.profilePicturePath, profileImageView, this, PictureType.Profile); } var editProfileButtonImageView = new UIImageView(new RectangleF(220, 20, 24, 24)); editProfileButtonImageView.ContentMode = UIViewContentMode.ScaleAspectFill; editProfileButtonImageView.Image = UIImage.FromBundle("EditMenu"); editProfileButtonImageView.Layer.MasksToBounds = true; var tapGestureRecognizerEdit = new UITapGestureRecognizer(this, new ObjCRuntime.Selector("TapProfilePictureSelector:")); editProfileButtonImageView.AddGestureRecognizer(tapGestureRecognizerEdit); editProfileButtonImageView.UserInteractionEnabled = true; userName = new UILabel(new RectangleF(20, 120, 220, 20)); userName.Font = UIFont.SystemFontOfSize(14.0f); userName.TextAlignment = UITextAlignment.Center; userName.TextColor = UIColor.White; userName.Text = LoginController.userModel.name; var dividerLineView = new UIView(new RectangleF(20, 145, 220, 0.5f)); dividerLineView.BackgroundColor = UIColor.FromRGB(80, 80, 80); var pagesItems = new MenuPagesModel().MenuItems; var pagesTableView = new UITableView(new RectangleF(20, 150, 220, (pagesItems.Count * 40) - 10)); pagesTableView.ContentInset = new UIEdgeInsets(0, 20, 0, 0); pagesTableView.BackgroundColor = UIColor.Clear; pagesTableView.ScrollEnabled = false; new MenuTableViewController(pagesTableView, pagesItems, menuViewController); var dividerLineView2 = new UIView(new RectangleF(20, (float)pagesTableView.Frame.Y + (float)pagesTableView.Frame.Height + 15, 220, 0.5f)); dividerLineView2.BackgroundColor = UIColor.FromRGB(80, 80, 80); var filterLabel = new UILabel(new RectangleF(20, (float)dividerLineView2.Frame.Y + 5, 220, 20)); filterLabel.Font = UIFont.BoldSystemFontOfSize(12.0f); filterLabel.TextAlignment = UITextAlignment.Left; filterLabel.TextColor = UIColor.FromRGB(80, 80, 80); filterLabel.Text = "Filter"; var filterTipLabel = new UILabel(new RectangleF(20, (float)dividerLineView2.Frame.Y + 5, 220, 20)); filterTipLabel.Font = UIFont.BoldSystemFontOfSize(9.0f); filterTipLabel.TextAlignment = UITextAlignment.Right; filterTipLabel.TextColor = UIColor.FromRGB(196, 155, 9); filterTipLabel.Text = "You may select more than one"; var filterItems = new MenuFilterModel().MenuItems; var filterTableView = new UITableView(new RectangleF(26, (float)filterLabel.Frame.Y + 15, 214, filterItems.Count * 40)); filterTableView.ContentInset = new UIEdgeInsets(0, 14, 0, 0); filterTableView.SeparatorColor = UIColor.FromRGB(80, 80, 80); filterTableView.BackgroundColor = UIColor.Clear; filterTableView.ScrollEnabled = false; new MenuTableViewController(filterTableView, filterItems, menuViewController); var dividerLineView3 = new UIView(new RectangleF(20, (float)filterTableView.Frame.Y + (float)filterTableView.Frame.Height + 15, 220, 0.5f)); dividerLineView3.BackgroundColor = UIColor.FromRGB(80, 80, 80); #region Hashtag Menu //var dividerLineView3 = new UIView(new RectangleF(20, (float)filterTableView.Frame.Y + (float)filterTableView.Frame.Height + 25, 220, 0.5f)); //dividerLineView3.BackgroundColor = UIColor.Black; //var hashtagLabel = new UILabel(new RectangleF(20, (float)dividerLineView3.Frame.Y + 5, 220, 20)); //hashtagLabel.Font = UIFont.BoldSystemFontOfSize(12.0f); //hashtagLabel.TextAlignment = UITextAlignment.Left; //hashtagLabel.TextColor = UIColor.Black; //hashtagLabel.Text = "Hashtag"; //var hashtagText = new UITextField(new RectangleF(20, (float)hashtagLabel.Frame.Y + 30, 220, 40)); //hashtagText.BorderStyle = UITextBorderStyle.Bezel; //hashtagText.Placeholder = "inserts tags to filter here"; #endregion #region Logout Button var logoutModel = new MenuLogoutModel(); var logoutButton = new UIButton(new RectangleF(0, (float)dividerLineView3.Frame.Y + 5, (float)View.Frame.Width, 40)); //logoutButton.BackgroundColor = UIColor.FromRGB(50, 50, 50); logoutButton.TouchUpInside += (object sender, EventArgs e) => { CredentialsService.DeleteCredentials(); LoginController.tokenModel = null; LoginController.userModel = null; var loginController = menuViewController.Storyboard.InstantiateViewController("LoginNavController"); if (loginController != null) { menuViewController.PresentViewController(loginController, true, null); } }; var logoutIcoImageView = new UIImageView(); logoutIcoImageView.ContentMode = UIViewContentMode.ScaleAspectFit; logoutIcoImageView.Layer.MasksToBounds = true; logoutIcoImageView.TranslatesAutoresizingMaskIntoConstraints = false; logoutIcoImageView.Image = UIImage.FromBundle(logoutModel.ImageName); var logoutTitleLabel = new UILabel(); logoutTitleLabel.Font = UIFont.SystemFontOfSize(14); logoutTitleLabel.Text = logoutModel.Title; logoutTitleLabel.TextColor = UIColor.White; logoutTitleLabel.TranslatesAutoresizingMaskIntoConstraints = false; logoutButton.Add(logoutIcoImageView); logoutButton.Add(logoutTitleLabel); logoutButton.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-48-[v0(24)]-20-[v1]-8-|", new NSLayoutFormatOptions(), "v0", logoutIcoImageView, "v1", logoutTitleLabel)); logoutButton.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-8-[v0(24)]", new NSLayoutFormatOptions(), "v0", logoutIcoImageView)); logoutButton.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:|-10-[v0(24)]", new NSLayoutFormatOptions(), "v0", logoutTitleLabel)); #endregion scrollView.AddSubview(profileImageView); scrollView.AddSubview(userName); scrollView.AddSubview(editProfileButtonImageView); scrollView.AddSubview(dividerLineView); scrollView.AddSubview(pagesTableView); scrollView.AddSubview(dividerLineView2); scrollView.AddSubview(filterLabel); scrollView.AddSubview(filterTipLabel); scrollView.AddSubview(filterTableView); scrollView.AddSubview(dividerLineView3); #region Hashtag Menu //scrollView.Add(dividerLineView3); //scrollView.Add(hashtagLabel); //scrollView.Add(hashtagText); #endregion scrollView.AddSubview(logoutButton); var scrollHeight = 20 + profileImageView.Frame.Height + 10 + userName.Frame.Height + 25 + dividerLineView.Frame.Height + 5 + pagesTableView.Frame.Height + 15 + dividerLineView2.Frame.Height + 5 + filterLabel.Frame.Height + 10 + filterTableView.Frame.Height + 5 + dividerLineView3.Frame.Height + 5 + logoutButton.Frame.Height + 40; if (scrollHeight > View.Frame.Height) { scrollView.ContentSize = new CGSize(View.Frame.Width, scrollHeight); } else { scrollView.ContentSize = new CGSize(View.Frame.Width, View.Frame.Height); } View.AddSubview(scrollView); }