2012-08-06 94 views
2

我已經開發了一個登錄表單(用戶名,密碼和提交按鈕)使用MySQL連接通過我的android應用程序中的soap web服務。在這裏我忘記我的密碼意味着我無法訪問我的帳戶,那麼訪問我的帳戶的方式如何。所以當我忘記我的密碼時,請點擊忘記密碼textview,然後忘記密碼活動。在這裏,當我輸入我的電子郵件ID意味着我的密碼從MySQL數據庫中檢索併發送給我的電子郵件ID。忘記密碼發送到Android的註冊電子郵件

我該怎麼辦,請指導我。 這是我的web服務代碼:

public class Login { 
public String authentication(String userName,String password){ 

    String retrievedUserName = ""; 
String retrievedPassword = ""; 
String status = ""; 
try{ 

Class.forName("com.mysql.jdbc.Driver"); 
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root",""); 
PreparedStatement statement = con.prepareStatement("SELECT * FROM customers WHERE login = '"+userName+"'"); 
ResultSet result = statement.executeQuery(); 

while(result.next()){ 
retrievedUserName = result.getString("login"); 
retrievedPassword = result.getString("password"); 
} 

if(retrievedUserName.equals(userName)&&retrievedPassword.equals(password)){ 
    status = "Success!"; 

} 

    else{ 
    status = "Login fail!!!"; 
    } 

    } 
    catch(Exception e){ 
    e.printStackTrace(); 
    } 
    return status; 

    } 

    } 

這是我忘記web服務的代碼是:

public class ForgetPassword { 
    public String authentication(String Email){ 
    String retrievedEmail = ""; 
    String status = ""; 
    try{ 

    Class.forName("com.mysql.jdbc.Driver"); 
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/pro","root",""); 
    PreparedStatement statement = con.prepareStatement("SELECT password FROM customers WHERE email = '"+Email+"'"); 
    ResultSet result = statement.executeQuery(); 

    while(result.next()){ 

retrievedEmail = retrievedEmail + result.getString("password"); 
    retrievedEmail = result.getString("email"); 
    } 

    if(retrievedEmail.equals(Email)){ 
     status = "Your password has been sent to your email address"; 
     } 

    else{ 
    status = "No such user exist"; 
     } 
     } 
     catch(Exception e){ 
     e.printStackTrace(); 
     } 
    return retrievedEmail; 
     } 
     } 

DIS是我的Android代碼忘記密碼:

 public class ForgetPassword extends Activity { 
     private final String NAMESPACE = "http://ws.userlogin.com"; 
     private final String URL = "http://192.168.1.168:8085/Login/services/ForgetPassword?wsdl"; 
     private final String SOAP_ACTION = "http://ws.userlogin.com/authentication"; 
     private final String METHOD_NAME = "authentication"; 
     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.forget_password); 
     Button submit = (Button) findViewById(R.id.submit); 
     submit.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View arg0) { 
     loginAction(); 

     } 
      }); 
      } 

     private void loginAction(){ 
     SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
     boolean isUserValidated = true; 
     EditText Email = (EditText) findViewById(R.id.email); 
     String email = Email.getText().toString(); 


     PropertyInfo unameProp =new PropertyInfo(); 
     unameProp.setName("Email");//Define the variable name in the web service method 
     unameProp.setValue(email);//set value for userName variable 
     unameProp.setType(String.class);//Define the type of the variable 
     request.addProperty(unameProp);//Pass properties to the variable 



       SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
       envelope.setOutputSoapObject(request); 
       HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 

       try{ 
       androidHttpTransport.call(SOAP_ACTION, envelope); 
      SoapPrimitive response = (SoapPrimitive)envelope.getResponse(); 
      String status = response.toString(); 
      TextView result = (TextView) findViewById(R.id.tv_status); 
      result.setText(response.toString()); 
      if(status.equals("Success!")) 
      { 

       // ADD to save and read next time 
        String strUserName = Email.getText().toString().trim(); 

        if (null == strUserName || strUserName.length() == 0) 
           { 
         // showToast("Enter Your Name"); 
        Email.setError("Email is required!"); 
     isUserValidated = false; 
        } 
      } 
      if(isUserValidated) 
      { 


          Intent intent = new Intent(ForgetPassword.this,AndroidLoginExampleActivity.class); 


          startActivity(intent); 

      } 




            else 
            { 
             Intent i = new Intent(getApplicationContext(), ForgetPassword.class); 
             startActivity(i); 
            } 
            } 


    catch(Exception e){ 

      } 
     } 

     } 

請大家幫幫我,怎麼樣去做這個?

+1

您發佈了很多代碼。你需要哪些幫助?你需要哪些具體的幫助? – 2012-08-06 04:37:44

+0

如果我忘記我的密碼意味着去​​忘記密碼activity.here當我輸入我的電子郵件ID意味着我的密碼是從MySQL數據庫檢索並將其發送到我的電子郵件ID。 – user1575906 2012-08-06 04:42:24

+0

你需要一個按鈕或者登錄活動的東西,用戶可以點擊啓動'ForgetPassword'活動。你有這樣的事嗎? – 2012-08-06 04:47:32

回答

0

從Java發送郵件的標準方式是JavaMail API。該鏈接中的示例代碼應該適用於發送密碼提示等簡單消息。

相關問題