Project

General

Profile

« Previous | Next » 

Revision 49406

Added by Sofia Baltzi over 6 years ago

Fic errors! It works!

View differences:

modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/RemindUsernameServlet.java
1 1
package eu.dnetlib.openaire.usermanagement;
2 2

  
3 3
import com.unboundid.ldap.sdk.LDAPException;
4
import eu.dnetlib.openaire.user.utils.EmailSender;
4 5
import eu.dnetlib.openaire.user.utils.LDAPActions;
5 6
import org.apache.log4j.Logger;
6 7
import org.springframework.beans.factory.annotation.Autowired;
......
29 30
    @Autowired
30 31
    private LDAPActions ldapActions;
31 32

  
32
    //private EmailActions emailActions;
33
    @Autowired
34
    private EmailSender emailSender;
33 35

  
34 36
    private Logger logger = Logger.getLogger(RemindUsernameServlet.class);
35 37

  
......
44 46

  
45 47
        try{
46 48
            String username = ldapActions.getUsername(formEmail);
47
            if ( username != null && !username.isEmpty()) {
48
                //emailActions.sendUsernameReminder(formEmail);
49
            if (username != null && !username.isEmpty()) {
49 50

  
51
                String verificationCodeMsg = "Hello,\n" +
52
                        "\n" + "A username reminder has been requested for your OpenAIRE account.\n" +
53
                        " Your username is "+ username + ". Thank you. ";
54

  
55
                String verificationCodeSubject = "Your OpenAIRE username";
56

  
57
                emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg);
58

  
50 59
            } else {
51 60
                request.getSession().setAttribute("message", "User not found");
52 61
                response.sendRedirect("./remindUsername.jsp");
53 62
            }
54 63

  
55

  
56 64
        } catch (LDAPException ldape) {
57 65
            //TODO create error page
58 66
            logger.error("Could not find user with email " + formEmail, ldape);
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ForgotPasswordServlet.java
8 8
import org.springframework.beans.factory.annotation.Autowired;
9 9
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
10 10

  
11
import javax.servlet.RequestDispatcher;
11 12
import javax.servlet.ServletConfig;
12 13
import javax.servlet.ServletException;
13 14
import javax.servlet.http.HttpServlet;
......
46 47

  
47 48
        String formEmail = request.getParameter("email");
48 49

  
49
        logger.debug("I am in do post for " + formEmail);
50
        
51 50
        if (formEmail == null) {
52 51
            request.getSession().setAttribute("message", "Error reading email.");
53 52
            response.sendRedirect("./forgotPassword.jsp");
......
56 55
        try {
57 56

  
58 57
            String username = ldapActions.getUsername(formEmail);
59

  
60 58
            if (username == null) {
61 59
                request.getSession().setAttribute("message", "User does not exist.");
62 60
                response.sendRedirect("./forgotPassword.jsp");
......
67 65

  
68 66
                Timestamp timestamp = new Timestamp(creationDate.getTime());
69 67

  
70
                //logger.info("verificationCode = " + verificationCode);
71

  
72 68
                if (!verificationActions.verificationEntryExists(username)) {
73 69
                    verificationActions.addVerificationEntry(username, verificationCode.toString(), timestamp);
74 70

  
......
82 78
                        "password, you will need to submit this verification code in order to verify that the\n" +
83 79
                        "request was legitimate.\n" +
84 80
                        "\n" +
85
                        "The verification code is" + verificationCode.toString() + "\n Thank you";
81
                        "The verification code is " + verificationCode.toString() + "\n Thank you";
86 82

  
87 83
                String verificationCodeSubject = "Your OpenAIRE password reset request";
88 84

  
89 85
                emailSender.sendEmail(formEmail, verificationCodeSubject, verificationCodeMsg);
90

  
91 86
            }
92 87

  
93

  
94 88
        } catch (LDAPException ldape) {
95 89
            //TODO create error page
96 90
            request.getSession().setAttribute("message", "Error sending email.");
......
98 92
        }
99 93

  
100 94
        response.setContentType("text/html");
95
//        try {
96
////            request.getSession().setAttribute("email", formEmail);
97
////            request.getSession().setAttribute("username", ldapActions.getUsername(formEmail));
98
////            request.setAttribute("email", formEmail);
99
//            request.setAttribute("username", ldapActions.getUsername(formEmail));
100
//            RequestDispatcher rd = request.getRequestDispatcher("./verify.jsp");
101
//            rd.forward(request, response);
102
////            RequestDispatcher rd = request.getRequestDispatcher("ForgotPasswordServlet");
103
////            rd.forward(request, response);
104
////
105
////            logger.info("Stelnwwww");
106
////
107
//        } catch (LDAPException e) {
108
//            e.printStackTrace();
109
//            logger.info("LDAP error" + e);
110
//            request.getSession().setAttribute("message", "Error getting username.");
111
//            response.sendRedirect("./forgotPassword.jsp");
112
//        } catch (ServletException ex) {
113
//            ex.printStackTrace();
114
//            logger.info("Dispacher error" + ex);
115
//        }
116

  
101 117
        response.sendRedirect("./verify.jsp");
102 118
    }
103 119

  
modules/dnet-openaire-users/trunk/src/main/java/eu/dnetlib/openaire/usermanagement/ResetPasswordServlet.java
2 2

  
3 3
import eu.dnetlib.openaire.user.utils.LDAPActions;
4 4
import eu.dnetlib.openaire.user.utils.VerificationActions;
5
import org.apache.log4j.Logger;
5 6
import org.springframework.beans.factory.annotation.Autowired;
6 7
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
7 8

  
......
30 31
    @Autowired
31 32
    private LDAPActions ldapActions;
32 33

  
34
    private Logger logger = Logger.getLogger(ResetPasswordServlet.class);
35

  
33 36
    @Override
34 37
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
35 38
        response.setContentType("text/html");
36 39
        PrintWriter printWriter = response.getWriter();
37 40

  
41
        String username = request.getParameter("username");
38 42
        String password = request.getParameter("password");
39
        String confirmPassword = request.getParameter("confirmPassword");
43
        String confirmPassword = request.getParameter("password_conf");
40 44

  
41
        if (password.equals(confirmPassword)) {
42
            //TODO update ldap
43
            //ldapActions.update()
45
        //logger.info("username: " + username);
46
        logger.info("password: " + password);
47
        logger.info("confirmPassword: " + confirmPassword);
48

  
49
        //String username = (String)request.getAttribute("username");
50

  
51
        logger.info("username: " + username);
52

  
53
        if (password.equals(confirmPassword) && username != null) {
54

  
55

  
56
            logger.info("username: " + username);
57
            try {
58

  
59
                ldapActions.resetPassword(username, password);
60
                logger.info("password reseted");
61

  
62
            } catch (Exception e) {
63
                e.printStackTrace();
64
                request.getSession().setAttribute("message", "Error reseting password.");
65
                response.sendRedirect("./verify.jsp");
66
            }
44 67
        }
45 68

  
46 69
        response.sendRedirect("./success.jsp");
modules/dnet-openaire-users/trunk/src/main/webapp/verify.jsp
49 49
                      <div id="registerForm">
50 50
                        <form action="verifyCode" method="POST" role="form" class="m-t" id="register_form">
51 51
                          <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
52
                          <%--<input type="hidden" name="username" value="${username}"/>--%>
52 53
                          <div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
53 54
                          <div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
54 55
                            <div class="form-group">
modules/dnet-openaire-users/trunk/src/main/webapp/resetPassword.jsp
47 47
                  <div class="uk-width-1-3@m uk-align-center">
48 48
                      <!-- REGISTER FORM -->
49 49
                      <div id="registerForm">
50
                        <form target="changePassword" method="POST" role="form" class="m-t" id="register_form" >
50
                        <form action="resetPassword" method="POST" role="form" class="m-t" id="register_form" >
51
                          <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
51 52
                          <div class="alert alert-success" aria-hidden="true" style="display: none;"></div>
52 53
                          <div class="alert alert-danger" aria-hidden="true" style="display: none;"></div>
53 54
                            <div class="form-group">
......
58 59
                                <input id="password_conf" name="password_conf" type="password" placeholder="Confirm password" class="form-control"></div>
59 60
                              <div class="uk-margin uk-grid-small uk-child-width-auto uk-grid uk-text-left uk-grid-stack" uk-grid="">
60 61
                              <div class="uk-width-1-1 uk-grid-margin uk-first-column">
61
                                <button type="button" class="uk-button uk-button-primary" onclick="return validateForm();">Submit</button>
62
                                <button type="submit" class="uk-button uk-button-primary" onclick="return validateForm();">Submit</button>
62 63
                              </div>
63 64
                            </div>
64 65
                        </form>
modules/dnet-openaire-users/trunk/src/main/webapp/remindUsername.jsp
36 36
    </div>
37 37
    <div class=" uk-section  uk-margin-small-top tm-middle custom-main-content" id="tm-main">
38 38
      <div class="uk-container uk-container-small uk-margin-medium-top  uk-margin-small-bottom uk-text-center">
39
        <h2 class="uk-h2 uk-margin-small-bottom">Forgot usernmame</h2>
39
        <h2 class="uk-h2 uk-margin-small-bottom">Forgot usermame</h2>
40 40
        <div uk-grid="" class="uk-grid uk-grid-stack">
41 41
          <div class="tm-main uk-width-1-2@s uk-width-1-1@m  uk-width-1-1@l uk-row-first uk-first-column uk-align-center">
42 42
            <div class="uk-grid ">

Also available in: Unified diff