It is not entirely clear how to process (implement the service correctly) username and password data. Data username and password are in the database. Tell me ideas in which direction to move.

login.html

<div class="container"> <p><br/></p> <div class="row"> <div class="col-md-4 col-md-offset-4"> <div class="panel panel-default"> <div class="panel-body" style="background-color: transparent"> <div class="page-header"> <h1>Log in</h1> </div> <!-- Start Form--> <form method="post" name="loginForm"> <!-- Start gorm-group username--> <div class="form-group"> <label for="exampleInputEmail1">Username or email</label> <div class="input-group"> <span class="input-group-addon" id="icon1"><span class="glyphicon glyphicon-user"></span></span> <input type="text" class="form-control" name="userLogin" id="exampleInputEmail1" ng-model="username"> </div> <label id="userLoginLabel" for="exampleInputEmail1"></label> </div> <!-- Start gorm-group password--> <div class="form-group"> <label for="exampleInputPassword1">Password</label> <div class="input-group"> <span class="input-group-addon" id="icon2"><span class="glyphicon glyphicon-lock"></span></span> <input type="password" class="form-control" name="userPassword" id="exampleInputPassword1" ng-model="password"> </div> <label id="passwordLabel" for="exampleInputPassword1" style="color:red"></label> </div> <div class="checkbox"> <label> <input type="checkbox" name="rememberMe">Remember me </label> </div> <hr/> <button type="submit" value="Submit" name="loginSubmit" class="btn btn-success" ng-click="login()">Log in</button> <a href="#"> <button type="button" name="signUpSubmit" class="btn btn-primary">Register </button> </a> <a href="#">Forgot your password?</a> </form> <script type="text/javascript"> </script> <!-- End Form--> </div> </div> </div> </div> </div> 

LoginController.js

 'use strict'; angular.module('Login').controller('LoginController', function ($scope, $state, $cookies, AuthenticationService) { $scope.login = function() { AuthenticationService.signIn($scope.username, $scope.password, function onSuccess(payload) { $state.go("dashboard"); }, function onError() { $state.go("login"); } ); } }); 

AuthenticationService.js

 'use strict'; app.factory('AuthenticationService', function (Network, $cookies) { return { signIn: function (username, password, onSuccess, onError) { Network.sendPost("/services/authentication/signIn", {"login": username, "password": password}, onSuccess, onError); }, signOut: function(onSuccess) { Network.sendGet("/services/authentication/signOut", {}, onSuccess); } }; }); 
  • Do you need to process on the server side or on the UI side? And what do you want with them (data) to do. - Vartlok
  • I need to process on the server side and somehow report the status (OK or error). Data is needed for Spring Security to create a full-fledged Authentication object and put it in the SecurityContextHolder. - Vasilii Zvarich

1 answer 1

I did this, when I open the page, I send a request to the server, the server checks the session, finds the user returns the data, if the data is correct then the user is authorized, it’s all in the menu directive and authorization service, that is, if some page is updated, the request will be sent and response received

  $rootScope.$on('$routeChangeStart', function (event) { url = $location.url(); 

This thing checks the user's rights and discards it before the page loads.

  • And how does the server find the user? Is authentication-manager used for this in service? - Vasilii Zvarich
  • finds a user in session, I don’t use authentication-manager - Serge Esmanovich