성준영

desktop-app 로그인 페이지 (electron)

const {app, BrowserWindow} = require('electron')
const path = require('path')
const url = require('url')
var client = require('electron-connect').client;
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
let win
client.create(win);
function createWindow () {
// Create the browser window.
win = new BrowserWindow({width: 800, height: 600})
win = new BrowserWindow({width: 900, height: 520})
// and load the index.html of the app.
win.loadURL(url.format({
......
'use strict';
var gulp = require('gulp');
var electron = require('electron-connect').server.create();
gulp.task('default', function () {
// Start browser process
electron.start();
// Restart browser process
gulp.watch('app.js', electron.restart);
// Reload renderer process
gulp.watch(['index.html', 'style.css', 'logic.js'], electron.reload);
});
\ No newline at end of file
......@@ -11,16 +11,65 @@
<!-- jquery -->
<script src="public/js/jquery-3.2.1.min.js"></script>
<!-- materizlize -->
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.98.2/js/materialize.min.js"></script>
<script>if (window.module) module = window.module;</script>
<!-- sweetalert -->
<script src="public/js/sweetalert.min.js"></script>
<link rel="stylesheet" type="text/css" href="public/css/sweetalert.css">
<!-- style -->
<link rel="stylesheet" type="text/css" href="style.css">
<script>require('electron-connect').client.create()</script>
<script>if (window.module) module = window.module;</script>
</head>
<body>
<script src="./logics.js"></script>
<script src="./logic.js"></script>
<div class="logoTitle">
<div class="imageWrapper">
<div class="layer">
</div>
</div>
<div class="title">KLAS 강의자료 다운로더</div>
<div class="desc">
강의자료를 다운받는 절차가 너무 귀찮아 만들게 되었습니다. <br/>
사실 만들고 나니까 이래나 저래나 귀찮긴 마찬가지인 것 같습니다. <br/>
아이디 / 패스워드는 로컬에만 저장되니 안심하고 사용하세요 :)
</div>
<div class="me">
문의 : 경희대학교 컴공 12 성준영 ( wnsdud1861@gmail.com )
</div>
</div>
<div class="loginForm">
<div class="input-field col s6 id">
<input placeholder="2012104095" id="id" type="text" class="validat id">
<label for="pw">경희대학교 학번</label>
</div>
<div class="input-field col s6 pw">
<input placeholder="KLAS 비밀번호" id="pw" type="password" class="validat id">
<label for="pw">KLAS 비밀번호</label>
</div>
<div class="loginBtnWrapper">
<button id="loginBtn" class="waves-effect waves-light btn #424242 grey darken-3">다운받으러 가기</button>
</div>
</div>
<div class="listWrapper">
<div class="lectureListWrapper">
</div>
<div class="fileListWrapper">
<h1>KLAS FILE DOWNLOADER</h1>
</div>
</div>
<button class="testBtn">테스트</button>
</body>
</html>
......
......@@ -35,14 +35,14 @@ exports.login = function (id, pw) {
}, function (err, res, body) {
if (err) {
if (err.code === 'ESOCKETTIMEDOUT') {
reject(' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ');
reject({code:'KLAS_TIMEOUT', message: ' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ'});
} else {
reject(' 알수없는 에러가 발생했어요!.');
reject({code:'UNKNOWN_ERR', message: ' 알수없는 에러가 발생했어요!'});
}
} else if (j.getCookies("https://klas.khu.ac.kr").length === 0) {
reject(' 로그인에 실패했습니다!');
reject({code:'LOGIN_FAIL', message: ' 로그인에 실패했어요!'});
} else {
resolve('success');
resolve({code:'SUCCESS'});
}
})
});
......@@ -63,7 +63,7 @@ exports.getLecture = function () {
}, function (err, res, body) {
if (err) {
console.log(err);
reject(' 파싱 중 에러가 발생했어요!');
reject({code:'CONNECT_ERR', message: ' 페이지 접근 중 에러가 발생했어요!'});
} else {
resolve(body);
}
......@@ -99,7 +99,11 @@ exports.getLectureLink = function (getLectureBody) {
lectureLinkList[i].link = 'https://klas.khu.ac.kr' + $(this).attr('href')
});
resolve(lectureLinkList);
if(lectureLinkList.length === 0){
reject({code:'LOGIN_ERR', message: ' 학번과 비밀번호를 확인해주세요!'});
} else {
resolve(lectureLinkList);
}
})
};
......@@ -176,9 +180,9 @@ exports.getClassPageBody = function (lectureLinkObj) {
}, function (err, res, body) {
if (err) {
if (err.code === 'ESOCKETTIMEDOUT') {
reject(' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ');
reject({code:'KLAS_TIMEOUT', message: ' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ'});
} else {
reject(' 알수없는 에러가 발생했어요!.');
reject({code:'UNKNOWN_ERR', message: ' 알수없는 에러가 발생했어요!.'});
}
} else {
resolve(body);
......
......@@ -21,4 +21,14 @@ exports.getLectureFileLinks = function(lectureLink, cb){
.catch(function(err){
cb(err);
})
};
exports.isValidIdPw = function(id, pw, cb){
functions.login(id, pw)
.then(function(){
cb(true);
})
.catch(function(){
cb(false);
})
};
\ No newline at end of file
......
/**
* Created by junyoung on 2017. 6. 7..
*/
let klasFD = require('./klasFD/module');
let userLectures = [];
$(document).ready(function () {
// 앱 시작하면 로그인 바로 체크
// checkLoginState(function(isValid){
// if(isValid){
// swal({
// title: "로그인 되었습니다!",
// type: "success",
// confirmButtonText: "OK",
// confirmButtonColor: "#424242",
// });
// $('.loginForm').hide();
// } else {
// // 로그인 실패
// swal({
// title: "로그인에 실패했습니다!",
// text: "다시 로그인해주세요!",
// type: "error",
// confirmButtonText: "OK",
// confirmButtonColor: "#424242",
// });
// }
// });
$('#loginBtn').click(function () {
let id = $('#id').val();
let pw = $('#pw').val();
klasFD.getLectureList(id, pw, function (res) {
console.log(res);
if (res.code) {
// 로그인 실패
swal({
title: "로그인에 실패했습니다!",
text: res.message,
type: "error",
confirmButtonText: "OK",
confirmButtonColor: "#424242",
});
return;
} else {
// 로그인 성공
localStorage.setItem('id', id);
localStorage.setItem('pw', pw);
console.log('LOGIN SUCCESS');
console.log(localStorage);
userLectures = res;
}
});
})
function checkLoginState(cb) {
klasFD.isValidIdPw(localStorage.getItem('id'), localStorage.getItem('pw'), cb);
}
});
\ No newline at end of file
/**
* Created by junyoung on 2017. 6. 7..
*/
var klasFD = require('./klasFD/module');
$(document).ready(function(){
$('.testBtn').click(function(){
klasFD.getLectureList('2012104095', 'Sung167300', function(res){
console.log(res);
var lectureLinkObj = res[2];
klasFD.getLectureFileLinks(lectureLinkObj, function(res){
console.log(res);
})
});
})
});
\ No newline at end of file
{
"name": "klasfd-desktop-app",
"version": "0.1.0",
"main": "main.js",
"main": "app.js",
"devDependencies": {
"electron": "^1.6.10"
"electron": "^1.6.10",
"electron-connect": "^0.6.1",
"gulp": "^3.9.1"
},
"dependencies": {
"klas-file-downloader": "^0.2.7"
"klas-file-downloader": "^0.2.7",
"sweetalert": "^1.1.3"
}
}
......
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
@font-face {
font-family:'BMDOHYEON';
src: url(/public/fonts/BMDOHYEON.ttf) format('truetype');
}
\ No newline at end of file
font-family: 'BMDOHYEON';
src: url(public/fonts/BMDOHYEON.ttf) format('truetype');
}
body {
margin: 0;
}
.logoTitle {
width: 100%;
}
.imageWrapper {
background: url(public/images/main_image.gif) center center no-repeat;
background-size: cover;
width: 100%;
height: 300px;
}
.layer {
background-color: rgba(0, 0, 0, 0.6);
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 300px;
}
.title {
position: fixed;
top: 120px;
right: 30px;
font-family: BMDOHYEON;
font-size: 40px;
color: white
}
.desc {
font-size: 12px;
text-align: right;
position: fixed;
top: 190px;
right: 30px;
font-family: Arial;
color: #ffffff;
}
.me {
text-align: right;
position: fixed;
top: 260px;
right: 30px;
font-family: Arial;
color: #ffffff;
}
.loginForm {
width: 100%;
height: auto;
padding: 3% 5% 3% 5%;
}
.id, .pw {
padding: 2%;
width: 49%;
display: inline-block;
}
.loginBtnWrapper {
width: 100%;
}
.input {
width: 100%;
}
/* label focus color */
.input-field input[type=text]:focus + label, .input-field input[type=password]:focus + label {
color: #424242;
}
/* label underline focus color */
.input-field input[type=text]:focus, .input-field input[type=password]:focus {
border-bottom: 1px solid #424242;
box-shadow: 0 1px 0 0 #424242;
}
#loginBtn {
width: 100%;
}
......
......@@ -35,14 +35,14 @@ exports.login = function (id, pw) {
}, function (err, res, body) {
if (err) {
if (err.code === 'ESOCKETTIMEDOUT') {
reject(' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ');
reject({code:'KLAS_TIMEOUT', message: ' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ'});
} else {
reject(' 알수없는 에러가 발생했어요!.');
reject({code:'UNKNOWN_ERR', message: ' 알수없는 에러가 발생했어요!'});
}
} else if (j.getCookies("https://klas.khu.ac.kr").length === 0) {
reject(' 로그인에 실패했습니다!');
reject({code:'LOGIN_FAIL', message: ' 로그인에 실패했어요!'});
} else {
resolve('success');
resolve({code:'SUCCESS'});
}
})
});
......@@ -63,7 +63,7 @@ exports.getLecture = function () {
}, function (err, res, body) {
if (err) {
console.log(err);
reject(' 파싱 중 에러가 발생했어요!');
reject({code:'PARSING_ERR', message: ' 파싱 중 에러가 발생했어요!'});
} else {
resolve(body);
}
......@@ -153,14 +153,14 @@ exports.selectLecture = function (lectureLinkList) {
/**
* @author sungjunyoung
* @description 강의실 링크의 url 을 받아서 HTML 를 리턴해주는 함수
* @param {String} lectureLink - 강의실 URL
* @param {String} lectureLinkObj - 강의명, 링크 오브젝트
* @returns {*|Promise}
*/
exports.getClassPageBody = function (lectureLink) {
exports.getClassPageBody = function (lectureLinkObj) {
return new Promise(function (resolve, reject) {
let url = lectureLink.link;
let url = lectureLinkObj.link;
let headers = {
'Cookie': 'COURSE_MENU_NAME=%uAC15%uC758%uC2E4',
......@@ -176,9 +176,9 @@ exports.getClassPageBody = function (lectureLink) {
}, function (err, res, body) {
if (err) {
if (err.code === 'ESOCKETTIMEDOUT') {
reject(' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ');
reject({code:'KLAS_TIMEOUT', message: ' 클라스 요청 응답시간이 너무 길어요... ㅠㅠ'});
} else {
reject(' 알수없는 에러가 발생했어요!.');
reject({code:'UNKNOWN_ERR', message: ' 알수없는 에러가 발생했어요!.'});
}
} else {
resolve(body);
......
......@@ -38,7 +38,7 @@ if (!flags.id) {
console.log(result);
})
.catch(function (err) {
console.log(err);
console.log(err.message);
});
} else {
var selectLecture;
......@@ -58,7 +58,7 @@ if (!flags.id) {
console.log(result);
})
.catch(function (err) {
console.log(err);
console.log(err.message);
})
}
......