0

I am using ui.router for my routes in angular. Here is what I am trying to do:

I have my router file where I have defined states like this:

state('login',{
url:'/login',
views:{
    'slot1':{
    templateUrl:'app/modules/authentication/authentication.html',
    controller:'AuthenticationController',
    controllerAs:'authCntrl'
}}})

What I want to do is to log the user in is they come with a URL in this format

http://someapp.io/login?user=name&pass=423%%$dsad32

Now how do I define the route URL and how to access the user and pass in my controller. Don't need full code, just the concepts or link to documentation would do.

This is how my controller looks like:

(function(){
angular.module("app.auth",[]).
controller("AuthenticationController", function( $state, $stateParams, AuthenticationService, LoadingService){
var self = this;
console.log($stateParams);
}

And this logs the following to console:

Object {}

EDIT:

Strangely, if I change url in my router to this:

url:'/instore_login?user=&pass='

I am able to get these values. Is this even right?

2 Answers 2

1

Your state definition needs to explicitly state that it expects parameters. There are more than one way of doing this with uirouter. The simplest is to add it to your URL definition :

url: '/login?user&pass', 

You should always be vigilant handling user credentials. This approach seems like it might be a bad code smell. Can you talk a bit in your original question what your plans are with this controller and state and we can make sure you are not opening yourself to a security issue.

Sign up to request clarification or add additional context in comments.

1 Comment

This will actually be an auto generated URL that nobody will be looking at. This is just for internal use. This application is not running in browser, rather a CEF app.
0

in your AuthenticationController, inject $stateParams it should be an object like

{user: "name", pass: "423%%$dsad32"}

2 Comments

I updated my question with controller code as well. This is what I tried first, but not getting anything.
as per your code update, like Martin said add parameters to URL definition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.