Advertisement
Guest User

Untitled

a guest
Apr 7th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. >leganto(raiz)
  2. ---> controller
  3. -------> ControllerGlobal.php
  4. -------> OutrosControllesDeObjetos
  5.  
  6. ---> model
  7. -------> ModelDeObjetos
  8.  
  9. ---> view
  10. -------> objeto
  11. -----------> CRUDdeCadaObjeto
  12.  
  13. ---> libs
  14. ---> css
  15. ---> imgs
  16. ---> js
  17.  
  18. ---> ajax
  19. -------> arquivosDeRequisicaoAjax
  20.  
  21. ---> index.php
  22.  
  23. site/account/create //vai instânciar o controller account e executar seu método create
  24.  
  25. private function create()
  26. {
  27. $title = "Registre-se no Leganto"; // titulo da página
  28. $icon = "plus"; // icone da página
  29.  
  30. // quando o formulário de cadastro for enviado, com token de proteção
  31. if(isset($_POST['userinsertrequest']) and $_POST['userinsertrequest'] == $_SESSION['token'])
  32. {
  33. try
  34. {
  35. $user = array(); // cria array com dados
  36. foreach ($_POST as $key => $value)
  37. {
  38. $user[$key] = addslashes(htmlentities($value));
  39. }
  40. // chama model que faz o insert
  41. $insert = $this->model->prepareNewUser($user);
  42. if($insert)
  43. {
  44. // se registrou volta pra tela de login
  45. header("Location:{$_SESSION['self']}");
  46. }
  47. else
  48. { // se não fala que houve um erro desconhecido
  49. $error = "Houve um error ao gravar o usuário.";
  50. }
  51. }
  52. catch(Exception $ex)
  53. { // pega erro de validação de dados do model
  54. $error = $ex->getMessage();
  55. }
  56. }
  57.  
  58. // inclui meu view de cadastro
  59. include 'view/account/user-create.php';
  60. }
  61.  
  62. $(function()
  63. {
  64. // quando meu formulário for submetido
  65. $("form[name = fm-register-user]").submit(function()
  66. {
  67. alert("ENVIOU"); // alerta funcionou
  68. $.ajax({
  69. type: "POST",
  70. url: "account/create", // tenta requisitar a função de criar
  71. data: { // pego meus dados incluindo o token
  72. name: $("input[name = name]").val(),
  73. email : $("input[name = email]").val(),
  74. date : $("input[name = date]").val(),
  75. username : $("input[name = username]").val(),
  76. password : $("input[name = password]").val(),
  77. confirmpassword : $("input[name = confirmpassword]").val(),
  78. ocupation : $("input[name = ocupation]").val(),
  79. history : $("input[name = history]").val(),
  80. userinsertrequest : $("input[name = userinsertrequest]").val()
  81. } ,
  82. success: function(retorno) {
  83. alert(retorno); // dou alerta na minha mensagem de retorno
  84.  
  85. }
  86. });
  87. });
  88. });
  89.  
  90. <?php
  91. /**
  92. * Created by PhpStorm.
  93. * User: Leonardo Vilarinho
  94. * Date: 10/03/2016
  95. * Time: 14:51
  96. */
  97.  
  98. $printError = (isset($error))
  99. ? "<div class='text-danger text-center'><strong>{$error}</strong></div>"
  100. : "";
  101.  
  102. $_SESSION['token'] = md5(time());
  103. $_SESSION['title'] = (!empty($title)) ? $title : "";
  104. /*
  105. "usuarios",
  106. array("username", "email", "password",
  107. "image", "name", "date",
  108. "ocupation", "history", "active", "token"),
  109. * */
  110. ?>
  111. <section class="row">
  112.  
  113. <div class="col-md-6 col-md-offset-3">
  114. <div class="panel panel-success">
  115. <div class="panel-heading">
  116. <h3 class="panel-title">
  117. <i class="fa fa-<?php echo (!empty($icon)) ? $icon : ""; ?>"></i>
  118. <?php echo (!empty($title)) ? $title : ""; ?>
  119. </h3>
  120. </div>
  121. <?php echo $printError; ?>
  122.  
  123. <form method="post" name="fm-register-user">
  124. <div class="panel-body">
  125. <table class="table form-group-sm">
  126. <tr class="text-center text-muted">
  127. <td colspan="10">
  128. <input name="image" type="file" accept=".jpg, .png">
  129. <img src="<?php echo $_SESSION['self'] ?>imgs/cover.jpg" style="width: 100px;" class="img-circle profile">
  130. <p>Foto do Perfil</p>
  131. </td>
  132. </tr>
  133. <tr>
  134. <td colspan="1">Nome Completo:</td>
  135. <td colspan="9">
  136. <input name="name" maxlength="255" required placeholder="Nome Completo" type="text" class="form-control"/>
  137. </td>
  138. </tr>
  139. <tr>
  140. <td colspan="1">Email:</td>
  141. <td colspan="7">
  142. <input name="email" maxlength="200" required placeholder="Email" type="email" class="form-control email validar-email"/>
  143. </td>
  144. <td colspan="1">Nascimento:</td>
  145. <td colspan="1">
  146. <input name="date" required type="date" class="form-control"/>
  147. </td>
  148. </tr>
  149. <tr>
  150. <td colspan="1">Usuário:</td>
  151. <td colspan="5">
  152. <input name="username" maxlength="20" required placeholder="Usuário" type="text" class="form-control"/>
  153. </td>
  154. <td colspan="4" class="text-muted">
  155. <p>(Sem espaços e acentos.)</p>
  156. </td>
  157. </tr>
  158. <tr>
  159. <td colspan="1">
  160. Senha:
  161. </td>
  162. <td colspan="7">
  163. <input name="password" maxlength="15" id="senha" required placeholder="Senha" type="password" class="form-control" />
  164. </td>
  165. <td colspan="1" class="confirm">
  166. Senha:
  167. </td>
  168. <td colspan="1" class="confirm">
  169. <input name="comfirmpassword" maxlength="15" id="senha2" required placeholder="Confirmar Senha" type="password" class="form-control" />
  170. </td>
  171. </tr>
  172. <tr>
  173. <td colspan="10">
  174. <div class="barprogress text-center" style="color: white; border: 1px solid #b4b5b2;">
  175. <div>.</div>
  176. </div
  177. </td>
  178. </tr>
  179. <tr>
  180. <td colspan="1">Ocupação:</td>
  181. <td colspan="9">
  182. <input name="ocupation" maxlength="255" required placeholder="Ocupação" type="text" class="form-control" />
  183. </td>
  184. </tr>
  185. <tr>
  186. <td colspan="1">Sobre:</td>
  187. <td colspan="9">
  188. <textarea placeholder="Conte-nos sua história..." maxlength="255" name="history" required class="form-control"></textarea>
  189. <div class="text-right count">
  190. <p>0 / 255</p>
  191. </div>
  192.  
  193. </td>
  194. </tr>
  195. </table>
  196. <input name="userinsertrequest" value="<?php echo $_SESSION['token']; ?>" type="hidden" />
  197.  
  198. </div>
  199. <div class="panel-footer text-center">
  200. <a class="btn btn-danger" href="<?php echo $_SESSION['self']; ?>" >Cancelar</a>
  201. <input value="Criar" type="submit" class="btn btn-success" />
  202. </div>
  203. </form>
  204. </div>
  205. </div>
  206. </section>
  207.  
  208. <?php
  209. $_SESSION['scripts'] = "<script src='{$_SESSION['self']}libs/formzin.js'></script>";
  210. $_SESSION['scripts'] .= "<script src='{$_SESSION['self']}js/verify-password.js'></script>";
  211. $_SESSION['scripts'] .= "<script src='{$_SESSION['self']}js/profile-inputs.js'></script>";
  212. $_SESSION['scripts'] .= "<script src='{$_SESSION['self']}ajax/register-user.js'></script>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement