Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @see HttpServlet#HttpServlet()
- */
- public Loginaction() {
- super();
- // TODO Auto-generated constructor stub
- }
- /**
- * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- doPost(request,response);
- }
- /**
- * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
- */
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- HttpSession session = request.getSession(true);
- String username = request.getParameter("nom");
- String password = request.getParameter("pass");
- UserDAO user = new UserDAO();
- boolean result = user.authentification(username, password);
- BaseUser user1 = user.getusername(username);
- if(result == true){
- session.setAttribute("user", user1);
- request.getRequestDispatcher("Liste_Projets.jsp").forward(request, response);
- }else{
- request.getRequestDispatcher("wrong_list.jsp").forward(request, response);
- }
- }
- public class UserDAO extends BaseUser{
- public boolean authentification(String login, String mdp){
- BaseUser user = getusername(login);
- if(user!=null){
- if(user.getLogin().equals(login) && user.getPassword().equals(mdp))
- return true;
- else
- return false;
- }
- }
- public BaseUser getusername(String login) {
- Session session = HibernateUtil.currentSession();
- Transaction tx = null;
- BaseUser user = null;
- try {
- tx = session.getTransaction();
- tx.begin();
- Query query = session.createQuery("from User where LOGIN='"+login+"'");
- user = (BaseUser)query.uniqueResult();
- tx.commit();
- } catch (Exception e) {
- if (tx != null) {
- tx.rollback();
- }
- e.printStackTrace();
- } finally {
- HibernateUtil.closeSession();
- }
- return user;
- }
- package suivi.base;
- import java.io.Serializable;
- /*
- * @hibernate.class
- * table="User"
- */
- public abstract class BaseUser implements Serializable {
- private int hashCode = Integer.MIN_VALUE;
- // primary key
- private java.lang.String _login;
- // fields
- private java.lang.String _nomPrenom;
- private java.lang.String _password;
- private java.lang.String _login;
- // constructors
- public BaseUser () {
- initialize();
- }
- /**
- * Constructor for primary key
- */
- public BaseUser (java.lang.String _login) {
- this.setLogin(_login);
- initialize();
- }
- /**
- protected void initialize () {}
- /**
- * Return the unique identifier of this class
- * @hibernate.id
- * generator-class="vm"
- * column="LOGIN"
- */
- public java.lang.String getLogin () {
- return _login;
- }
- /**
- * Set the unique identifier of this class
- * @param _login the new ID
- */
- public void setLogin (java.lang.String _login) {
- this._login = _login;
- this.hashCode = Integer.MIN_VALUE;
- }
- /**
- * Return the value associated with the column: NOM_PRENOM
- */
- public java.lang.String getNomPrenom () {
- return _nomPrenom;
- }
- /**
- * Set the value related to the column: NOM_PRENOM
- * @param _nomPrenom the NOM_PRENOM value
- */
- public void setNomPrenom (java.lang.String _nomPrenom) {
- this._nomPrenom = _nomPrenom;
- }
- /**
- * Return the value associated with the column: PASSWORD
- */
- public java.lang.String getPassword () {
- return _password;
- }
- /**
- * Set the value related to the column: PASSWORD
- * @param _password the PASSWORD value
- */
- public void setPassword (java.lang.String _password) {
- this._password = _password;
- }
- public String toString () {
- return super.toString();
- }
- <script type="text/javascript">
- function Annuler(){
- document.login.reset();
- }
- function valider()
- {
- var ok = true;
- if (document.getElementById("nom").value.length<1)
- {
- ok = false;
- document.getElementById("erreurLogin").innerHTML="*Obligatoire";
- }
- var x = document.getElementById("pass").value;
- if(x == "")
- {
- ok = false;
- document.getElementById("erreurLogin1").innerHTML="*Obligatoire";
- }
- if(ok)
- {
- document.login.submit()
- }
- }
- </script>
- ...//code
- <body>
- <form name="login" method="Post" action="Loginaction">
- <tr height="40px" valign="bottom">
- <td width="150px"> </td>
- <td class="StyleLabel">Identifiant: </td>
- <td width="1px"></td>
- <td colspan="2" ><input class="input" type="text" size="24" maxlength="20" name="nom" id="nom"></td>
- <td><label class="asterix" id="erreurLogin"></label></td>
- </tr>
- <tr height="40px" valign="bottom">
- <td width="150px"></td>
- <td width="100px" class="StyleLabel" >Mot de passe: </td>
- <td width="1px"></td>
- <td colspan="2" > <input class="input" type="password" size="24" autocomplete="off" maxlength="20" name="pass" id="pass"> </td>
- <td ><label class="asterix" id="erreurLogin1"></label></td>
- </tr>
- <tr height="40px" >
- <td> </td>
- <td colspan="3" align="center"> <img src="images/btnValid.gif" name="valid" value="valid" type="submit" onclick="valider();"/></td>
- <td colspan="3" align="center"> <img src="images/btnAnnul.gif" onclick="Annuler();"/></td>
- </tr>
- </table>
- public boolean authentification(String login, String mdp){
- BaseUser user = getusername(login);
- if(user!=null )
- {
- if(user.getLogin().equals(login) && user.getPassword().equals(mdp))
- return true;
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement