성준영

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

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