2017-09-11 6 views
2

私のアプリケーションは2つのログインを持っています。ユーザーはアプリケーションアカウントまたはFacebookにログインできます。今はFacebookアカウント、ユーザー名、電子メール、パスワード私のアプリケーションアカウント登録で同じテーブルに保存できますか?私はlocalhostとphpデータベースを使用しています。私はアプリケーションを開発するためにアンドロイドスタジオを使用しています。なぜなら、自分のアプリケーションでFacebookアカウントでユーザーがログインして、新しいアカウントを作成したい場合、ちょうど今。誰かが私の質問を理解したいと思う。以下は私のログインがあり、アプリケーションのアカウントコードを登録します。アンドロイドアプリケーションで別のアカウントでアカウントを作成する

ログイン:

<?php 

require_once '../includes/DbOperations.php'; 

$response = array(); 

if($_SERVER['REQUEST_METHOD']=='POST'){ 
if(isset($_POST['username']) and isset($_POST['password'])){ 
    $db = new DbOperations(); 

    if($db->userLogin($_POST['username'], $_POST['password'])){ 
     $user = $db->getUserByUsername($_POST['username']); 
     $response['error'] = false; 
     $response['user_id'] = $user['user_id']; 
     $response['email'] = $user['email']; 
     $response['username'] = $user['username']; 


    }else{ 
     $response['error'] = true; 
     $response['message'] = "Invalid username or password";   
    } 

}else{ 
    $response['error'] = true; 
    $response['message'] = "Required fields are missing"; 
} 
} 

echo json_encode($response); 
?> 

レジスタ:

<?php 

require_once '../includes/DbOperations.php'; 

$response = array(); 

if($_SERVER['REQUEST_METHOD']=='POST'){ 
if(
    isset($_POST['username']) and 
     isset($_POST['email']) and 
      isset($_POST['password'])) 
    { 
    //operate the data further 

    $db = new DbOperations(); 

    $result = $db->createUser( $_POST['username'], 
           $_POST['password'], 
           $_POST['email'] 
          ); 
    if($result == 1){ 
     $response['error'] = false; 
     $response['message'] = "User registered successfully"; 
    }elseif($result == 2){ 
     $response['error'] = true; 
     $response['message'] = "Some error occurred please try again";   
    }elseif($result == 0){ 
     $response['error'] = true; 
     $response['message'] = "It seems you are already registered, please choose a different email and username";      
    } 
}else{ 
    $response['error'] = true; 
    $response['message'] = "Required fields are missing"; 
} 
}else{ 
$response['error'] = true; 
$response['message'] = "Invalid Request"; 
} 

echo json_encode($response); 
+0

他の回答がありますか? –

答えて

0

私はこのような状況で行うことは、データベース内のユーザー・データと一緒に店の電子メールです。それと並んで、ユーザー名も保存します(ユーザー名の重複を避けるため)。したがって、ユーザーが新しいアカウントを作成した場合、そのメールIDが存在するかどうかがチェックされます。存在する場合は、パスワードをリセットするメッセージを表示してください。

関連する問題