fix(skillrack): update login to j_security_check endpoint, exact ion-icon medal and points regex extraction, and rename input label to SkillRack Login ID
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled
Some checks failed
Deploy RIT Freshers Hub to VPS / Deploy to Live VPS (push) Has been cancelled
This commit is contained in:
@@ -75,89 +75,46 @@ public class SkillrackService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Core scraping method:
|
* Core scraping method using SkillRack's container security:
|
||||||
* 1. GET the SkillRack login page to obtain JSESSIONID cookie + ViewState
|
* 1. GET https://www.skillrack.com/faces/ui/profile.xhtml to establish JSESSIONID session
|
||||||
* 2. POST login form with email + password + ViewState
|
* 2. POST to https://www.skillrack.com/faces/ui/j_security_check with j_username (Login ID) & j_password
|
||||||
* 3. Parse the resulting profile/dashboard page for stats
|
* 3. GET https://www.skillrack.com/faces/candidate/profileview.xhtml with authenticated session & parse HTML
|
||||||
*/
|
*/
|
||||||
public boolean fetchAndUpdateProfile(SkillrackProfile profile, String rawPassword) {
|
public boolean fetchAndUpdateProfile(SkillrackProfile profile, String rawPassword) {
|
||||||
try {
|
try {
|
||||||
log.info("Fetching SkillRack stats for: {}", profile.getSkillrackEmail());
|
log.info("Fetching SkillRack stats for Login ID: {}", profile.getSkillrackEmail());
|
||||||
|
|
||||||
// Step 1: GET login page to get session cookie + ViewState
|
String loginPageUrl = SKILLRACK_BASE + "/faces/ui/profile.xhtml";
|
||||||
Connection.Response loginPageRes = Jsoup.connect(LOGIN_URL)
|
String jSecurityCheckUrl = SKILLRACK_BASE + "/faces/ui/j_security_check";
|
||||||
|
|
||||||
|
// Step 1: GET login page to establish session cookie
|
||||||
|
Connection.Response pageRes = Jsoup.connect(loginPageUrl)
|
||||||
.method(Connection.Method.GET)
|
.method(Connection.Method.GET)
|
||||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
||||||
.timeout(15000)
|
.timeout(15000)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
Map<String, String> cookies = new HashMap<>(loginPageRes.cookies());
|
Map<String, String> cookies = new HashMap<>(pageRes.cookies());
|
||||||
Document loginDoc = loginPageRes.parse();
|
|
||||||
|
|
||||||
// Extract ViewState from hidden input
|
// Step 2: POST login credentials to j_security_check
|
||||||
String viewState = "";
|
|
||||||
Element vsEl = loginDoc.selectFirst("input[name=javax.faces.ViewState]");
|
|
||||||
if (vsEl != null) {
|
|
||||||
viewState = vsEl.attr("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find the login form and its ID
|
|
||||||
Element loginForm = loginDoc.selectFirst("form[id]");
|
|
||||||
String formId = loginForm != null ? loginForm.attr("id") : "j_idt4";
|
|
||||||
|
|
||||||
// Step 2: POST login credentials
|
|
||||||
Map<String, String> formData = new LinkedHashMap<>();
|
Map<String, String> formData = new LinkedHashMap<>();
|
||||||
formData.put(formId, formId);
|
formData.put("j_username", profile.getSkillrackEmail().trim());
|
||||||
formData.put("javax.faces.ViewState", viewState);
|
formData.put("j_password", rawPassword);
|
||||||
|
|
||||||
// Find email/username and password input fields
|
Connection.Response loginRes = Jsoup.connect(jSecurityCheckUrl)
|
||||||
Elements inputs = loginDoc.select("input[type=text], input[type=email], input[type=password]");
|
|
||||||
String emailFieldName = formId + ":j_idt6";
|
|
||||||
String passwordFieldName = formId + ":j_idt8";
|
|
||||||
|
|
||||||
for (Element input : inputs) {
|
|
||||||
String name = input.attr("name");
|
|
||||||
String type = input.attr("type");
|
|
||||||
if (type.equals("text") || type.equals("email")) {
|
|
||||||
emailFieldName = name;
|
|
||||||
} else if (type.equals("password")) {
|
|
||||||
passwordFieldName = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
formData.put(emailFieldName, profile.getSkillrackEmail());
|
|
||||||
formData.put(passwordFieldName, rawPassword);
|
|
||||||
|
|
||||||
// Find submit button name
|
|
||||||
Element submitBtn = loginDoc.selectFirst("input[type=submit], button[type=submit]");
|
|
||||||
if (submitBtn != null && submitBtn.hasAttr("name")) {
|
|
||||||
formData.put(submitBtn.attr("name"), submitBtn.attr("value"));
|
|
||||||
}
|
|
||||||
|
|
||||||
String formAction = LOGIN_URL;
|
|
||||||
if (loginForm != null && loginForm.hasAttr("action")) {
|
|
||||||
String action = loginForm.attr("action");
|
|
||||||
if (action.startsWith("http")) {
|
|
||||||
formAction = action;
|
|
||||||
} else {
|
|
||||||
formAction = SKILLRACK_BASE + action;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Connection.Response loginRes = Jsoup.connect(formAction)
|
|
||||||
.method(Connection.Method.POST)
|
.method(Connection.Method.POST)
|
||||||
.cookies(cookies)
|
.cookies(cookies)
|
||||||
.data(formData)
|
.data(formData)
|
||||||
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
.userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36")
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.header("Referer", LOGIN_URL)
|
.header("Referer", loginPageUrl)
|
||||||
.followRedirects(true)
|
.followRedirects(true)
|
||||||
.timeout(15000)
|
.timeout(15000)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
cookies.putAll(loginRes.cookies());
|
cookies.putAll(loginRes.cookies());
|
||||||
|
|
||||||
// Step 3: Fetch the profile/dashboard page with authenticated session
|
// Step 3: Fetch candidate profile page with authenticated session
|
||||||
Connection.Response profileRes = Jsoup.connect(PROFILE_URL)
|
Connection.Response profileRes = Jsoup.connect(PROFILE_URL)
|
||||||
.method(Connection.Method.GET)
|
.method(Connection.Method.GET)
|
||||||
.cookies(cookies)
|
.cookies(cookies)
|
||||||
@@ -168,11 +125,11 @@ public class SkillrackService {
|
|||||||
|
|
||||||
cookies.putAll(profileRes.cookies());
|
cookies.putAll(profileRes.cookies());
|
||||||
Document profileDoc = profileRes.parse();
|
Document profileDoc = profileRes.parse();
|
||||||
|
|
||||||
// Check if we're still on the login page (auth failed)
|
|
||||||
String bodyText = profileDoc.body().text();
|
String bodyText = profileDoc.body().text();
|
||||||
if (bodyText.contains("Incorrect email") || bodyText.contains("Login") && !bodyText.contains("Total Points")) {
|
|
||||||
// Try alternative dashboard URL
|
// Check if login failed (still redirected back to login page containing Login Id input)
|
||||||
|
if (bodyText.contains("Login Id") || bodyText.contains("Invalid") || !bodyText.contains("Candidate")) {
|
||||||
|
// Try alternative candidate manage profile page
|
||||||
Connection.Response dashRes = Jsoup.connect(SKILLRACK_BASE + "/faces/candidate/manageprofile.xhtml")
|
Connection.Response dashRes = Jsoup.connect(SKILLRACK_BASE + "/faces/candidate/manageprofile.xhtml")
|
||||||
.method(Connection.Method.GET)
|
.method(Connection.Method.GET)
|
||||||
.cookies(cookies)
|
.cookies(cookies)
|
||||||
@@ -181,8 +138,12 @@ public class SkillrackService {
|
|||||||
.timeout(15000)
|
.timeout(15000)
|
||||||
.execute();
|
.execute();
|
||||||
cookies.putAll(dashRes.cookies());
|
cookies.putAll(dashRes.cookies());
|
||||||
profileDoc = dashRes.parse();
|
Document dashDoc = dashRes.parse();
|
||||||
bodyText = profileDoc.body().text();
|
String dashText = dashDoc.body().text();
|
||||||
|
if (!dashText.contains("Login Id")) {
|
||||||
|
profileDoc = dashDoc;
|
||||||
|
bodyText = dashText;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4: Parse profile stats from the HTML
|
// Step 4: Parse profile stats from the HTML
|
||||||
@@ -215,53 +176,47 @@ public class SkillrackService {
|
|||||||
// ─── HTML Parsing ─────────────────────────────────────────────────
|
// ─── HTML Parsing ─────────────────────────────────────────────────
|
||||||
|
|
||||||
private boolean parseProfileStats(Document doc, SkillrackProfile profile) {
|
private boolean parseProfileStats(Document doc, SkillrackProfile profile) {
|
||||||
|
String html = doc.html();
|
||||||
boolean foundAnything = false;
|
boolean foundAnything = false;
|
||||||
String fullText = doc.body().text();
|
|
||||||
|
|
||||||
// Try to find stats from structured HTML elements (cards, spans, divs)
|
// 1. Extract Real Name from .ui-chip-text if available
|
||||||
// SkillRack typically shows stats in card-like containers
|
Element chipEl = doc.selectFirst(".ui-chip-text");
|
||||||
|
if (chipEl != null) {
|
||||||
// Look for numbers near keywords
|
String chipText = chipEl.text().trim();
|
||||||
foundAnything = parseFromRawText(fullText, profile);
|
if (chipText.contains("-")) {
|
||||||
|
String[] parts = chipText.split("-");
|
||||||
// Also try parsing from any table structures
|
if (parts.length >= 1 && !parts[0].trim().isEmpty()) {
|
||||||
Elements tables = doc.select("table");
|
profile.setStudentName(parts[0].trim());
|
||||||
for (Element table : tables) {
|
|
||||||
Elements rows = table.select("tr");
|
|
||||||
for (Element row : rows) {
|
|
||||||
Elements cells = row.select("td, th");
|
|
||||||
if (cells.size() >= 2) {
|
|
||||||
String label = cells.get(0).text().trim().toLowerCase();
|
|
||||||
String value = cells.get(cells.size() - 1).text().trim();
|
|
||||||
int num = parseIntSafe(value);
|
|
||||||
|
|
||||||
if (label.contains("code test") || label.contains("codetest")) {
|
|
||||||
profile.setCodeTestSolved(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("code tutor") || label.contains("codetutor")) {
|
|
||||||
profile.setCodeTutorSolved(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("code track") || label.contains("codetrack")) {
|
|
||||||
profile.setCodeTrackSolved(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("daily challenge") || label.contains("dc")) {
|
|
||||||
profile.setDcSolved(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("gold")) {
|
|
||||||
profile.setGoldMedals(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("silver")) {
|
|
||||||
profile.setSilverMedals(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("bronze")) {
|
|
||||||
profile.setBronzeMedals(num);
|
|
||||||
foundAnything = true;
|
|
||||||
} else if (label.contains("total") && label.contains("point")) {
|
|
||||||
profile.setTotalPoints(num);
|
|
||||||
foundAnything = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. Gold Medals (orange medal icon)
|
||||||
|
Matcher goldM = Pattern.compile("ion-md-medal\"\\s+style=\"color:orange\"></i>\\s*(\\d+)").matcher(html);
|
||||||
|
if (goldM.find()) {
|
||||||
|
profile.setGoldMedals(Integer.parseInt(goldM.group(1)));
|
||||||
|
foundAnything = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Silver Medals (grey medal icon)
|
||||||
|
Matcher silverM = Pattern.compile("ion-md-medal\"\\s+style=\"color:grey\"></i>\\s*(\\d+)").matcher(html);
|
||||||
|
if (silverM.find()) {
|
||||||
|
profile.setSilverMedals(Integer.parseInt(silverM.group(1)));
|
||||||
|
foundAnything = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Bronze Medals (brown medal icon)
|
||||||
|
Matcher bronzeM = Pattern.compile("ion-md-medal\"\\s+style=\"color:brown\"></i>\\s*(\\d+)").matcher(html);
|
||||||
|
if (bronzeM.find()) {
|
||||||
|
profile.setBronzeMedals(Integer.parseInt(bronzeM.group(1)));
|
||||||
|
foundAnything = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. Total Points / Score (brown flag icon)
|
||||||
|
Matcher pointsM = Pattern.compile("ion-md-flag\"\\s+style=\"color:brown\"></i>\\s*(\\d+)").matcher(html);
|
||||||
|
if (pointsM.find()) {
|
||||||
|
profile.setTotalPoints(Integer.parseInt(pointsM.group(1)));
|
||||||
|
foundAnything = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return foundAnything;
|
return foundAnything;
|
||||||
|
|||||||
@@ -1483,14 +1483,14 @@ export default function LeetcodeLeaderboard() {
|
|||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-bold text-slate-700 mb-1 flex items-center gap-1">
|
<label className="block text-xs font-bold text-slate-700 mb-1 flex items-center gap-1">
|
||||||
<Mail className="w-3.5 h-3.5 text-[#FF6B00]" /> SkillRack Email
|
<User className="w-3.5 h-3.5 text-[#FF6B00]" /> SkillRack Login ID (or Username)
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="email"
|
type="text"
|
||||||
required
|
required
|
||||||
value={srEmail}
|
value={srEmail}
|
||||||
onChange={(e) => setSrEmail(e.target.value)}
|
onChange={(e) => setSrEmail(e.target.value)}
|
||||||
placeholder="e.g. student@ritchennai.edu.in"
|
placeholder="e.g. 2117240070293@rgit"
|
||||||
className="w-full px-3.5 py-2.5 rounded-xl border border-[#E2E8F0] text-sm text-[#1E293B] focus:outline-none focus:border-[#F97316]"
|
className="w-full px-3.5 py-2.5 rounded-xl border border-[#E2E8F0] text-sm text-[#1E293B] focus:outline-none focus:border-[#F97316]"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user