package wotakutools.connect;
/**
 * 某tuneへアクセスするためのクラス
 * @author shun kawai
 */

import wotakutools.connect.Connect;
import wotakutools.connect.ConnectException.*;

import java.io.IOException;

import java.util.*;

import org.jsoup.*;
import org.jsoup.nodes.*;
import org.jsoup.Connection.*;

public class ConnectFortune
    extends wotakutools.connect.Connect {

    public static final String BASEURI = "https://fortunemusic.jp/";
    public static final String LOGINURI = BASEURI + "default/login/";
    public static final String MYPAGEURI = BASEURI + "mypage/";

    private Map <String, String> cookies;

    @Override
    public int login(String username, String password)
        throws java.io.IOException {
        // ログイン処理
        Connection con = Jsoup.connect(ConnectFortune.LOGINURI)
            .data("login_id", username)
            .data("login_pw", password)
            .data("submit", "ログイン")
            .method(Method.POST);
        Connection.Response response = con.execute();
        this.cookies = response.cookies();
        return response.statusCode();
    }

    @Override
    public Document connect(String URI)
        throws java.io.IOException {
        return Jsoup.connect(URI)
            .cookies(this.cookies)
            .get();
    }
}

@@ -225,24 +225,51 @@
 rg.jsoup.*;%0A
+import org.jsoup.select.*;%0A
 import org.j
@@ -278,24 +278,24 @@
 up.nodes.*;%0A
-
 import org.j
@@ -727,33 +727,85 @@
 a.io.IOException
- 
+,%0A               wotakutools.connect.ConnectException
 %7B%0A        // %E3%83%AD%E3%82%B0%E3%82%A4
@@ -1115,24 +1115,125 @@
 .cookies();%0A
+        if(this.loginCheck() == false)%0A            throw new LoginFaild(%22Bad username or password%22);%0A
         retu
@@ -1425,16 +1425,16 @@
 ookies)%0A
-
         
@@ -1450,11 +1450,396 @@
 );%0A    %7D
+%0A%0A    private boolean loginCheck()%0A        throws java.io.IOException%7B%0A        Document doc = this.connect(ConnectFortune.BASEURI);%0A        Elements navis = doc.getElementsByAttributeValue(%22id%22, %22globalNav%22);%0A        Element navi = navis.get(0);%0A        Elements forms = navi.getElementsByTag(%22form%22);%0A%0A        if(forms.size() == 1)%0A            return true;%0A        return false;%0A    %7D
 %0A%7D%0A

Throw Exception when LoginFaild to Fortune