Currently, my session storage looks like:
My user id and level are showing on the same line. How could this be? I created to vars in my Angular loginService like so:
'use strict';
app.factory('loginService',function($http, $location, sessionService){
return{
login:function(data,scope){
var $promise=$http.post('data/user.php',data); //send data to user.php
$promise.then(function(msg){
var uid=msg.data;
var pass=msg.data;
var level=msg.data;
if(uid){
//scope.msgtxt='Correct information';
sessionService.set('uid',uid);
//sessionService.set('lvl',level);
$location.path('/home');
}
if(level){
sessionService.set('level',level);
$location.path('/home');
}
else {
window.alert("Wrong credentials entered");
scope.msgtxt='incorrect information';
$location.path('/login');
}
});
},
then in my login script, its simple - it checks against my rows and returns the value of level according to the users password and username entered.
$user=json_decode(file_get_contents('php://input'));
if(isset($user))
{
session_start();
$useridname = $user->uid;
$userpass = md5($user->pass);
$_SESSION['uid']=$user->uid;
//get level
$sql = "SELECT lvl FROM dbo.users WHERE userid = '".$useridname."'
AND psw = ?";
$params = array($userpass);
$stmt = sqlsrv_query($conn,$sql,$params);
//if query does not work, return false
if($stmt === false){
die( print_r( sqlsrv_errors(), true));
}
$row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
if($row)
{
do{
//echo "You are being logged in... please wait!";
//$_SESSION['lvl']=$user->level;
print $_SESSION['level'] = $row['lvl'];
print $_SESSION['uid'];
For some odd reason, I can not for the life of me figure out how to get them to print separately on their own line. Without print, it won't print in the sessionStorage key and value fields. Can't figure this one out and ive been at it for a couple of hours now.
Any ideas from the Angular community?
edited (data.php):
$_SESSION['uid']=$user->uid;
$_SESSION['level']=$user->level;
//get userid and level from users table according to username and password entered
$sql = "SELECT lvl FROM dbo.users WHERE userid = '".$useridname."' AND psw = ?";
edited (services.js):
login:function(data,scope){
var $promise=$http.post('data/user.php',data); //send data to user.php
$promise.then(function(msg,lvl){
var uid=msg.data;
var pass=pass.data;
var level=lvl.data;
if(uid){
//scope.msgtxt='Correct information';
sessionService.set('uid',uid);
sessionService.set('level',level);
$location.path('/home');
}