Modify Xamarin.Forms page from Xamarin.iOS file - firebase

I'm working on a Xamarin.Forms app that uses Firebase Authentication. In order to make Firebase work, I have to create two different platform-specific files (iOS and Android) to process the Authentication tasks (like CreateNewUser and Login). I have a Xamarin.Forms page called "Payment Page" that asks a user to enter their e-mail and password, and submitting this page triggers the DependencyService to create the user account. On the Payment Page, I also have a small window that will appear if something goes wrong with the account creation process (specifically in this case, if a duplicate e-mail already exists in the Auth database).
My question is, if one of the Dependency files for iOS or Android catches a 'ERROR_EMAIL_ALREADY_IN_USE', how can I set the error dialog on the Payment Page to show (in other words, set its 'isVisible' property to 'true'). I've tried a number of things but so far cannot seem to reference elements in the PaymentPage (a Xamarin.Forms page) from the Xamarin.iOS Authentication page.
My Dependency code is as follows:
public void CreateNewUser(string email, string password, System.Collections.Specialized.NameValueCollection userData)
{
Auth.DefaultInstance.CreateUser(email, password, HandleAuthDataResultHandler);
}
async void HandleAuthDataResultHandler(AuthDataResult authResult, Foundation.NSError error)
{
if(error.UserInfo["error_name"].ToString() == "ERROR_EMAIL_ALREADY_IN_USE")
{
//What goes here to modify the Xamarin.Forms page??
}
else { }
}

MessagingCenter might be a good way to go https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/messaging-center
You can suscribe your viewmodel and post a message from the handler with the result.

in your XAML code behind
try {
// call your dependency service
} catch (Exception ex)
{
// update the UI
}
then in your DependencyService method, it should throw an exception when an error condition occurs

Related

Azure AD B2C Xamarin Forms - After Successful login OnAppearing method executing again

This is iOS specific issue.
I have completed all the steps suggested in document over here https://azure.microsoft.com/en-in/resources/samples/active-directory-b2c-xamarin-native/
In Andtoid it is working fine. But in iOS it is not returning back to application after successful login.
Yes, Login page is displaying properly we can enter the credentials over there but once login in successful then browser is closed but debugger not attaching back to application.
I have Eneabled Keychain access, Added Url Types in info.plist and also added below code to AppDelegate.cs
public override bool OpenUrl(UIApplication app, NSUrl url, NSDictionary options)
{
AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(url);
return true;
}
And on FInishLaunching event I have added below code
var authenticationService = DependencyService.Get();
// Default system browser
authenticationService.SetParent(null);
Actually I am calling SignInAsync method from OnAppearing event of view. So after successful validation OnAppearing event is firing again and it lost the previous flow.
Please let me know if I am missing something. Your help is much appreciated.
Thanks.

Appcenter push: dynamic navigation based on custom data

I'm wondering if I could get some help using AppCenter push in my Xamarin Forms app that targets Android & iOS.
Essentially, I've followed the instructions and I'm able to see the push notifications in my testing on Android. I understand that there are different behaviors between foreground and background notifications and have stepped through via the debugger when the PushNotificationReceived event happens..
The issue I'm having is I cannot find a reliable way to isolate when a user is entering the app because they tapped on a notification when the app is not loaded.
In my App.xaml.cs, I have the following:
protected override async void OnInitialized()
{
InitializeComponent();
Push.PushNotificationReceived += Push_PushNotificationReceived;
AppCenter.Start("ios={ios ID}" +
"uwp={Your UWP App secret here};" +
"android={android ID}",
typeof(Analytics), typeof(Crashes), typeof(Push));
await NavigationService.NavigateAsync("Splash"); // this is my splash screen that shows
}
private async void Push_PushNotificationReceived(object sender, PushNotificationReceivedEventArgs e)
{
if (e.CustomData != null)
{
if (e.CustomData.ContainsKey("roundId"))
{
string roundId = e.CustomData["roundId"];
//I want to navigate directly to this UI
await NavigationService.NavigateAsync($"IconNavigationPage/HomeView/Round?roundId={roundId}");
}
}
}
So, as you can see, under normal circumstances, the app will load the Splash view which does some loading, and redirects to a home view. When the notification is received and the user has the app running in the background, on Android, it's working fine. I changed my launch mode to SingleTop and added the following to my MainActivity.cs
protected override void OnNewIntent(Android.Content.Intent intent)
{
base.OnNewIntent(intent);
Push.CheckLaunchedFromNotification(this, intent);
}
The issue is, when the app is not running in the background, and I tap the notification, the Splash screen navigation call is called, then my navigation call in the PushNotificationReceived event. This essentially causes the app to load the UI that is defined in the event, for a second, then Splash UI redirects happen. This is due to the fact that OnInitialize() gets ran when the app is loaded from the Tap of the notification, when the app is not running in the background.
I have experimented in trying to implement the PushNotificationReceived event handler in the Android MainActivity.cs file, and I do see that this fires before the same PushNotificationReceived event handlers in the Shared project. Unfortunately it runs after the call to the LoadApplication, so my shared project's OnInitialize() gets fired first (which has that navigation call to Splash)
I guess what I'm looking for is some guidance, or maybe a point to a tutorial, on how I can accomplish notifying the Shared project's OnInitialize not to do the standard navigation to Splash, but rather do the navigation necessary for the Push Notification instead. I've search high and low, but all of tutorials / docs simply do a debug write to console proving that that the custom data that was passed is there, which I too can see, I cannot find anything that handles real-world use cases of a viable workflow to control navigation based on the tap of a notification.
Any help or guidance would be greatly appreciated.
Thank-you in advance.

E-mail confirmation working on registration but not logon in Asp.Net Core

I have a website which has a lot of users before implementing e-mail verification. I use ASP.NET Core 1.1
I want new users e-mails to be verified but not previously registered members....
So now if I add this line to Startup.cs:
options.SignIn.RequireConfirmedEmail = true;
previously registered users will need to have their e-mails validated and this is not practical in my site... If I set it to false then new users will receive an error if they open ConfirmEmail method... so I need a solution to be able to have it set to true but previously registered users are able to login without confirmation.
Thanks a lot
You could take that line out of Startup.cs and handle the logic in your controller...
For example, create a bit column in the AspNetUsers table 'previousUser', and default it to 0. Set all previous users to 1. Then in your Login action of your controller have a check like something below:
if (!await _userManager.IsEmailConfirmedAsync(user) && _context.Users.previousUser != true)
{
ModelState.AddModelError(string.Empty, "You must have a confirmed email to log in.");
return View(await BuildLoginViewModelAsync(model));
}
else
{
...sign in
]

ASP.NET MVC Windows Authenticate with extending properties

I need help of experts!
I write ASP.NET MVC 4 Intranet application. I using Windows Authentication, the domain name get through User.Identity.Name. I have a database with the configured data context, where more complete information about the user: Last name, First name, E-mail, etc. As well as a list of user access groups.
Needed to make sure that a user open a program, has received the required access from the database, his name brought up in the upper right corner of the page.
Now I have realized that with the use of OWIN Asp.Net Identity. I created a base controller that inherits the other controllers, it ordered CurrentUser method for the user and his SignIn:
protected ApplicationUser CurrentUser
{
get
{
var curUser = AppUserManager.FindByName(User.Identity.Name);
if (curUser != null)
SignInManager.SignIn(curUser, true, true);
else
curUser = new ApplicationUser();
return curUser;
}
}
protected ApplicationSignInManager SignInManager
{
get
{
return HttpContext.GetOwinContext().Get<ApplicationSignInManager>();
}
}
I understand that these operations are unnecessary, when you refresh the page every time it is necessary to drag into the database, users receive and make SignIn, which is unnecessary.
I'm sure you can realize all without using Asp.Net Identity. For example by expanding IPrincipal User, adding him to the field name, which are needed when displaying pages and adding once Roles from the database and save all in Cookies.
Please, help me! And sorry for my bad english...

ASP.NET MVC - Real time updates using Web Service

I'm trying to find examples on how to get real time updates using a web service in ASP.NET MVC (Version doesn't matter) and posting it back to a specific user's browser window.
A perfect example would be a type of chat system like that of facebooks' where responses are send to the appropriate browser(client) whenever a message has been posted instead of creating a javascript timer on the page that checks for new messages every 5 seconds. I've heard tons of times about types of sync programs out there, but i'm looking for this in code, not using a third party software.
What i'm looking to do specifically:
I'm trying to create a web browser chat client that is SQL and Web Service based in ASP.NET MVC. When you have 2-4 different usernames logged into the system they chat and send messages to each other that is saved in an SQL database, then when there has been a new entry (or someone sent a new message) the Web Service see's this change and then shows the receiving user the new updated message. E.G Full Chat Synced Chat using a Web Service.
The thing that really stomps me in general is I have no idea how to detect if something new is added to an SQL table, and also I have no idea how to send information from SQL to a specific user's web browser. So if there are people userA, userB, userC all on the website, i don't know how to only show a message to userC if they are all under the username "guest". I would love to know hot to do this feature not only for what i'm trying to create now, but for future projects as well.
Can anyone point me into the right direction please? I know SQL pretty well, and web services i'm intermediate with.
You can use SignalR for this task.
Via Scott Hanselman:
Create Asp.net mvc empty application
install nuget package of SignalR
Add new Controller (as example HomeController):
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
Create view Index with javascript references:
#Url.Content("~/Scripts/jquery-1.6.4.min.js")"
"#Url.Content("~/Scripts/jquery.signalR.js")"
and function:
$(function () {
var hub = $.connection.chatHub;
hub.AddMessage = function (msg) {
$('#messages').append('<li>' + msg + '</li>');
};
$.connection.hub.start().done(function() {
$('#send').click(function() {
hub.send($('#msg').val());
});
});
});
Create class ChatHub:
public class ChatHub:Hub
{
public void Send(string message)
{
Clients.AddMessage(message);
}
}

Resources