Handling Back button in Nativescript - nativescript-angular

I am developing an app by using Nativescript with Angular. According to our design, there is a dashboard when application is started. Now the thing I want to do is that when user click on back button in android, I want to confirm with user 'Are you sure you want to exit?'.
If user click OK, the app will be killed.
If user click No, the app will stay on dashboard page.
If you are aware of this, please share me how can I accomplish this.
Thanks & Best Regards,
Zaw Zaw Naing

You can create a service and maintain current page which can be passed if you want to implement something specific to page. Else you can directly implement logic within below service.
#Injectable()
export class BackService {
private currentPagePara: CurrentPageParameters; //Custom object only if required
constructor(
}
backHandler() {
if (application.android) {
application.android.on(application.AndroidApplication.activityBackPressedEvent, (data: application.AndroidActivityBackPressedEventData) => {
// Implement your logic here
});
} else if (application.ios) {
console.log("app ios")
}
}
}
Inject this service in base component and call backhandler
this._backService.backHandler()

Related

MSAL.Net and Xamarin.Forms having problem with redirect url

I am following this guide https://github.com/Azure-Samples/active-directory-xamarin-native-v2/tree/master/1-Basic
and have this code in my app.xaml.cs
public App()
{
PCA = PublicClientApplicationBuilder.Create(applicationClientId)
.WithTenantId("tenantidhere")
.WithRedirectUri($"msal{applicationClientId}://auth")
.WithIosKeychainSecurityGroup("com.microsoft.adalcache") // focussing on android first so ignore this one
.Build();
//...
}
I get the message that there is something wrong with the return url... and the continue button does not seem to work. I don't know if the issues are related or sepearate.
Here are my azure settings in the azure AD:
I felt that I had to switch back to the 'old experience' because the guides/tutorials etc. does not seem to reflect the current Azure UI.
You will have updated the value of DataScheme on MsalActivity.cs and AndroidManifest.xml with the correspondent clientId of your application.

Node / Angular 2: Update navbar and show sidebar after user login

This is my first project/application using Angular 2. And I am currently stuck in the login problem of the application. So, in my web app:
Expectations:
I load a login component for the first time. In this case, the navbar shows a "Sign In" button.
After correct login, I can go to a dashboard component. In the dashboard component, I can see a sidebar on the left side, and my navbar is updated to show the "Sign Out" button.
When I click "Sign Out", it should sign me out gracefully.
For a clearer picture, I've uploaded an album showing how the login and dashboard should look like, and the actual happening after login.
Reality:
I use localStorage from Angular 2 to store the current user in key currentUser and detect whether user is logged in. As long as it deoesn't value in the currentUser key, the login component works fine. Otherwise, it shows an empty dashboard with no title in it.
After the login, the sidebar and updated navbar is jumbled up with the login screen, while the dashboard is not showing up.
I've made a temporary Git repo to show you my code for now.
If you notice, the Angular frontend is connected to a Node.js backend. The Node.js backend works just fine.
I think the main problem points are in my usage of Observables (to tell every subscribing component that user is logged in), the authentication guard on the routes, and maybe the authentication service itself.
To meet the expectations above, I've tried to use Observables and emit the values to the subscribing components. However, the 'reality' points I've mentioned above happened, and I haven't known a way yet to fix it again.
So, can you help show me where the problem is, and what I can do to fix it? I would appreciate your input, thank you.
Finally, I found the problem.
The authentication guard was just delivering the Observable from this.authService.isLoggedInObservable() method. It doesn't deliver the proper value for the routes to know whether the user is actually logged in or not.
If you see in the repo, I use Observable<boolean> to tell the other components/routes whether I've logged in or not.
A workaround I did was to actually store a private variable inside the guard. I did this so that the canActivate() method inside the guard only returns that private variable: true means I'm logged in, false otherwise.
How to let that private variable know that I'm now logged in, and its value needs to change?
Within the constructor I made sure that the guard was subscribing for the Observable with that boolean value, and update that variable accordingly.
I just changed the code from AuthenticationGuard. Nothing less, nothing more.
import { Injectable } from "#angular/core";
import { Router, CanActivate } from "#angular/router";
import { Observable } from "rxjs";
import { AuthenticationService } from "./authentication.service";
#Injectable()
export class AuthenticationGuard implements CanActivate {
private isLoggedIn: boolean; // to store the "logged in" state
constructor(
private router: Router,
private authService: AuthenticationService) {
this.authService.isLoggedInObservable().subscribe((val) => {
this.isLoggedIn = val; // update as subscribed
// redirect to login page if not logged in yet
if (!val) this.router.navigate(["/login"]);
});
}
canActivate() { // only returns that private variable
return this.isLoggedIn;
}
}

Orchard - How to understand if I'm calling from Admin panel

I need to execute some code everytime I load a page, except if the page belongs to the admin panel. I created an IActionFilter and in the OnActionExecuting method I tried to check for the Controller name, but it isn't an optimal solution because there are a lot of different controllers being called from the dashboard. Is there a more efficient way to recognize if I'm loading a page of the admin panel?
Yes there is
using Orchard.UI.Admin;
&
if (AdminFilter.IsApplied(filterContext.RequestContext))
{
// This is an admin page, do nothing
return;
}

Symfony2, Security, registration and isEnable error

Guys there is a description about how to make 'isEnabled' (active\inactive account) on registration.
http://symfony.com/doc/current/cookbook/security/entity_provider.html#forbid-inactive-users
But there is NO description how to get this error on login action. For example I have working properly registration where user account default is inactive. After user login how can I get "inAcitve" if account is not activated by email link?
Is pretty easy: you can create a service that will act as a event listener
# app/config/config.yml
services:
your_bundle_name.login_listener:
class: FQN\Of\Your\Bundle\Class\Listener
tags:
- { kernel.event_listener, security.interactive_login}
tags part is there because, on bootstrap of your application, kernel will "attach" certain type of events to your service and will call a method on that service each time this event is raised.
So kernel.event_listener is there because every event listener have to be tagged that way (follow it as a "rule") and security.interactive_login will be fired as a user succesfully log in.
Your class could be something like
//omitting class declaration on purpose
public function onSecurityInteractiveLogin(InteractiveLoginEvent $event) {
$user = $event->getAuthenticationToken()->getUser();
if (!$user->isActive()) {
//do the proper action to display the error
}
}

SignalR - Can't create url for HubConnection

I started to work with SignalR on Visual Studio 2012, so far I got the basic hang of it, I guided myself through this example (You can browse the code in the page). I decided I wanted to add a REST service to said example, so I added a basic service to it and it worked.
The next step I wanted to take was to add a communication between the service and SignalR, so according to what the example showed to me, I only needed to create a HubConnection through the url in my project (in this case, the example uses the url http:localhost:4200). You can check the WorkerRoleHubConfiguration class, it has a method that has the next line:
return RoleEnvironment.GetConfigurationSettingValue("GUI_URL");
Where GUI_URL is http:localhost:4200.
In my service class then I just added a method with the following:
var url = RoleEnvironment.GetConfigurationSettingValue("http://localhost:4200");
try
{
HubConnection _connection = new HubConnection(url);
IHubProxy _hub = _connection.CreateProxy("SiteMonitR");
_hub.Invoke("displayResult");
}
catch (Exception ex)
{
error = ex.ToString();
}
But that throws an exception, this one.
I don't undertand why I can get the url in the same way the example does, as I'm doing everything as it's done on the Server class.
The goal I'm trying to achieve is that when an endpoint is accesed and something changes in my system, SignalR notifies to the clients connected to it.
I hope anyone can help me understand what's wrong with my work.
EDIT
I'm adding my ServiceConfiguration.Local.cscfg, my ServiceConfiguration.Cloud.cscfg and ServiceDefinition.csdef files as reference here, I think the problem should be around there but to be honest I got no idea as to why this isn't working.
EDIT 2
I'm getting the following exception at this line var url = RoleEnvironment.GetConfigurationSettingValue("http://localhost:4200");
The exception is:
SEHExcetion occurred. External component has thrown an exception.
The URL is for a GUI - it has to be a web interface for signalr to negotiate the hub connection. In the example, the hub (server) sends updates to connections coming from the configured URL - again a web interface (html page).
The logic to communicate needs to reside in the Server class and be called from the worker role. For example, after making a call to your service in the worker role, then call server.DoSomething("message") to invoke a message to the server. THat code would look something like:
public Class Server
{ ...
public void DoSomething(string message)
{
_hub.Invoke("doSomething", message);
}
...
}
Then in Server.Run() add:
// whenever a DoSomething is called
_hub.On<string>("doSomething", (message) => _hub.Invoke("doSomething", message));
And in SiteMonitRNotificationHub
public class SiteMonitRNotificationHub : Hub
{
...
public void DoSomething(string address)
{
Clients.doingSomething(address);
}
...
}
Finally in the controller script in the web gui:
c.siteMonitorHub
...
.on('doingSomething', function (message) {
c.doSomething(message);
})
and...
this.doSomething= function (message) {
// do something in your web page with message
};

Resources