Advertisement
Guest User

Untitled

a guest
Nov 2nd, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. /*
  2. * Create User After they complete the first part of the form.
  3. *
  4. */
  5. public function createUserFromOrder(Request $request)
  6. {
  7. $validation = $this->validate($request, [
  8. 'first_name' => 'required',
  9. 'last_name' => 'required',
  10. 'email' => 'required|confirm|unique:users,email',
  11. 'email_confirmation' => 'required'
  12. ]);
  13.  
  14. if ($validation->fails()) {
  15. return 'testing';
  16. $errors = $validation->errors();
  17. $errors = json_decode($errors);
  18.  
  19. return response()->json([
  20. 'success' => false,
  21. 'message' => $errors
  22. ], 422);
  23. }
  24.  
  25. $randomPassword = str_random(7);
  26. $createdSuccessfully = "<div class='alert alert-success' role='alert'><span class='status-available'> User Profile Created.</span></div>";
  27. $userData = [
  28. 'email' => $request->email,
  29. 'password' => $randomPassword,
  30. 'first_name' => $request->first_name,
  31. 'last_name' => $request->last_name,
  32. ];
  33.  
  34. $user = Sentinel::registerAndActivate($userData);
  35. $role = Sentinel::findRoleByName('patient');
  36. $role->users()->attach($user);
  37.  
  38. Sentinel::login($user, true);
  39.  
  40. $order = Order::create([
  41. 'program_id' => $request->program_id,
  42. 'program_type_id' => $request->program_type_id,
  43. 'amount' => 433,
  44. 'order_type' => 0,
  45. 'paid' => 0,
  46. 'status' => 0
  47. ]);
  48. $user->complete($order);
  49. $order->addAddon($request->input('addons'));
  50.  
  51. return $createdSuccessfully;
  52. }
  53.  
  54.  
  55. $.ajax({
  56. type: "POST",
  57. url: '{{action('OrderProcessController@createUserFromOrder') }}',
  58. data:
  59. {
  60. email: email,
  61. first_name: first_name,
  62. last_name: last_name,
  63. program_id: program_id,
  64. program_type_id: program_type_id,
  65. amount: amount,
  66. addons: addons
  67. },
  68. success:function(data){
  69. $("#user-created-confirmation").html(data);
  70. },
  71. error:function (){}
  72. }, function(){
  73. setTimeout(function() {
  74.  
  75. })
  76. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement