如何使用angularjs和php在另一个页面中显示当前用户详细信息?

时间:2017-03-13 18:24:05

标签: php angularjs

我已经创建了登录表单。将数据发布到数据库以检查电子邮件和密码的组合,如果满足则成功登录。

现在我在登录后重定向到个人资料页面。

我想在此个人资料页面中显示存储在数据库中的当前登录用户详细信息。 我使用ui-router进行导航。

我的login.html

<div class="col-lg-6 col-lg-offset-3 well " style="margin-top:1em; background-color:black; ">

  <h4 style="color:white; text-align:center;"> <strong> LOGIN  </strong> </h4>

</div>


<div class="col-lg-6 col-lg-offset-3 well" style="margin-bottom:13em;">

  <form name="login" ng-app="TempleWebApp" ng-controller="logCtrl" ng-submit="signin(login.$valid)" novalidate>

    <div class="form-group col-lg-12" ng-class="{ 'has-error' : login.email.$invalid && (login.email.$dirty || submitted)}">
      <label>Email</label>
      <input class="form-control" type="text" name="email" ng-model="useremail" placeholder="Email" ng-pattern="/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/" ng-required="true">
      <span class="help-block" ng-show="login.email.$invalid && login.email.$error.required && (login.email.$dirty || submitted)">
				          Email is required.</span>
      <span class="help-block" ng-show="login.email.$error.pattern">
				        Enter Valid  Email .</span>
    </div>


    <div class="form-group col-lg-12" ng-class="{ 'has-error' : login.password.$invalid && (login.password.$dirty || submitted)}">
      <label>Password</label>
      <input class="form-control" type="password" name="password" ng-model="userpassword" placeholder="Password" ng-required="true">
      <span class="help-block" ng-show="login.password.$invalid && login.password.$error.required && (login.password.$dirty || submitted)">
				          Password is required.</span>
    </div>

    <div class="col-lg-12 well " ng-repeat="error in errors" style="background-color:red; margin-top:0.5em;"> {{ error}} </div>
    <div class="col-lg-12 well" ng-repeat="msg in msgs" style="margin-top:0.5em;">
      <h5 style="color:green;">{{ msg}} </h5>
    </div>


    <button type="submit" class="btn btn-success col-lg-12"> 
				   <span ng-show="searchButtonText == 'REDIRECTING TO PROFILE PAGE'"><i class="glyphicon glyphicon-refresh spinning"></i></span>
                  {{ searchButtonText }}
				</button>


  </form>
</div>

我的登录角度控制器

app.controller('logCtrl', function($scope, $location, $http, $timeout) {

  $scope.errors = [];
  $scope.msgs = [];
  $scope.searchButtonText = "LOGIN";
  $scope.test = "false";

  $scope.signin = function(isValid) {

    // Set the 'submitted' flag to true
    $scope.submitted = true;
    $scope.errors.splice(0, $scope.errors.length); // remove all error messages
    $scope.msgs.splice(0, $scope.msgs.length);



    if (isValid) {

      $http.post('php/login.php', {
          'email': $scope.useremail,
          'pswd': $scope.userpassword

        })
        .success(function(data, status, headers, config) {
          if (data.msg != '') {
            $scope.msgs.push(data.msg);

            $scope.test = "true";
            $scope.searchButtonText = "REDIRECTING TO PROFILE PAGE";
            var goTopayment = function() {
              $scope.searchButtonText = "LOGIN";
              $location.path('/profile');
            };
            $timeout(goTopayment, 3000);

          } else {
            $scope.errors.push(data.error);
          }
        })
        .error(function(data, status) { // called asynchronously if an error occurs or server returns response with an error status.

          $scope.errors.push(status);
        });
    } // closing bracket for IF(isvalid)

  } // closing bracket for $scope.SIGNUP = function 	 




});

的login.php

<?php

$data = json_decode(file_get_contents("php://input"));

$uemail = mysql_real_escape_string($data->email);
$upswd = mysql_real_escape_string($data->pswd);


$con = mysql_connect('localhost', 'root', '');
mysql_select_db('registraion', $con);

$qry_em = 'select Email,Password,Status from users where Email ="' . $uemail . '" and Password ="' . $upswd . '" '; 
$qry_res = mysql_query($qry_em);
$res = mysql_fetch_assoc($qry_res);

if ( $res ['Email']==$uemail && $res ['Password']==$upswd && $res['Status']=='active')
	
	{
		
		$arr = array('msg' => "Logged in Successfully!!!", 'error' => '');
        $jsn = json_encode($arr);
        print_r($jsn);
		
	}
	
else
{
     $arr = array('msg' => "", 'error' => 'Email And Password Miss Match Or Your Account Is Not Activated Yet. Please Activate Account.');
    $jsn = json_encode($arr);
    print_r($jsn);
}

?>

profile.html

<div ng-controller="logCtrl" class="col-lg-12 well">
  <h4 style="text-align:center;">DETAILS</h4>

  <table class="table table-hover">
    <thead>
      <tr>
        <th>Name</th>
        <th>city</th>
        <th>gender</th>

      </tr>
    </thead>
    <tbody>
      <tr ng-repeat="user in data ">
        <td>{{user.Firstname}}</td>
        <td>{{user.City}}</td>
        <td>{{user.Gender}}</td>

      </tr>
    </tbody>

  </table>

</div>

如何在profile.html页面中获取当前登录的用户数据。

0 个答案:

没有答案