2015-04-29 18 views
6

तो मैं JSON वेब टोकन का उपयोग करके इस angular/Laravel 5 tutorial का पालन कर रहा हूं। मैं एक मुद्दे में भाग रहा हूँ।लार्वेल में उपयोगकर्ता बनाना 5

Route::post('/signup', function() { 
    $credentials = Input::only('email', 'password','name'); 

    try { 
     $user = User::create($credentials); 
    } catch (Exception $e) { 
     return Response::json(['error' => 'User already exists.'], Illuminate\Http\Response::HTTP_CONFLICT); 
    } 

    $token = JWTAuth::fromUser($user); 

    return Response::json(compact('token')); 
}); 

समस्या है, User::create($credentials); एन्क्रिप्ट नहीं करता पासवर्ड, जिसका अर्थ है, लॉगिन हमेशा असफल हो जायेगी:

यह इस प्रकार से एक उपयोगकर्ता बनाने का कहना है। मैंने इसे लैरावेल के डिफ़ॉल्ट पंजीकरण का उपयोग करके पाया।

मेरा सवाल है, मैं एक नया उपयोगकर्ता कैसे बना सकता हूं जो इसे सही तरीके से बनाता है?

उत्तर

12

आपको Hash helper class का उपयोग करके स्वयं को पासवर्ड हैश करना होगा। इसे आज़माएं:

Route::post('/signup', function() { 
    $credentials = Input::only('email', 'password','name'); 
    $credentials['password'] = Hash::make($credentials['password']); 
    try { 
     $user = User::create($credentials); 
    } catch (Exception $e) { 
     return Response::json(['error' => 'User already exists.'], Illuminate\Http\Response::HTTP_CONFLICT); 
    } 

    $token = JWTAuth::fromUser($user); 

    return Response::json(compact('token')); 
}); 
संबंधित मुद्दे