Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dennis 33 posts 238 karma points
    Jun 24, 2015 @ 11:31
    Dennis
    0

    Member login in single page app using AngularJS

    I am developing a single page app in Umbraco 7 using AngularJS. I need to login members to the site, but I can't find a good way to do this?

    Have someone experience and would like to share their knowledge with me?

  • Jan Skovgaard 11230 posts 23312 karma points MVP 6x admin c-trib
    Jun 24, 2015 @ 12:06
    Jan Skovgaard
    0

    Hi Dennis

    I don't think that a member service exists for AngularJS - Someone correct me if I'm wrong - However I'm thinking you might be able to create one yourself by using the Umbraco API and create your own member service perhaps?

    You can learn more about the Umbraco API here https://our.umbraco.org/documentation/Reference/Management-v6/

    Hope this helps a bit.

    /Jan

  • Dennis 33 posts 238 karma points
    Jun 24, 2015 @ 12:11
    Dennis
    1

    Yes I thought so. Oki I develop my own. I found this fine article on how to develop a login mechanism in AngularJS:

    http://brewhouse.io/blog/2014/12/09/authentication-made-simple-in-single-page-angularjs-applications.html

  • Shadman Kudchikar 1 post 71 karma points
    26 days ago
    Shadman Kudchikar
    0

    In the below example I created an oauth service that can be used for login and logut operation in the app. It internally depends on custom currentUser and formEncode service and angular built-in $http service. You can learn more about this angularjs service here.

    angular.module("app")
    .config(function ($provide) {
        $provide.provider("oauth", function () {
    
            var url = "/token";
    
            this.setUrl = function (newUrl) {
                url = newUrl;
            };
    
            this.$get = function ($http, formEncode, currentUser) {
    
                var processToken = function (username) {
                    return function (response) {
                        currentUser.profile.username = username;
                        currentUser.profile.token = response.data.access_token;
                        currentUser.save();
    
                        $http.get(`api/IdentityEmployee/${username}`).then(function (res) {
                            currentUser.profile.userInfo = res.data;
                            currentUser.save();
                        });
    
                        return username;
                    }
                };
    
                var login = function (username, password) {
    
                    var configuration = {
                        headers: {
                            "Content-Type": "application/x-www-form-urlencoded"
                        }
                    };
    
                    var data = formEncode({
                        username: username,
                        password: password,
                        grant_type: "password"
                    });
    
                    return $http.post(url, data, configuration).then(processToken(username));
                };
    
                var logout = function () {
                    currentUser.profile.username = "";
                    currentUser.profile.token = "";
                    currentUser.remove();
                };
    
                return {
                    login: login,
                    logout: logout
                };
            }
        });
    }); 
    
    angular.module("app").config(["oauthProvider", function(oauthProvider) {
    
    
    oauthProvider.setUrl('/another-token-url');
    }]);
    
Please Sign in or register to post replies

Write your reply to:

Draft