Dmitry Yu Okunev лет назад: 6
Родитель
Сommit
dfb9b0a642
8 измененных файлов с 118 добавлено и 15 удалено
  1. 3 0
      .gitmodules
  2. 2 0
      .meteor/packages
  3. 6 0
      .meteor/versions
  4. 14 0
      client/main.jsx
  5. 58 4
      imports/ui/Common.jsx
  6. 25 10
      imports/ui/Services.jsx
  7. 1 0
      packages/meteor-accounts-cas
  8. 9 1
      server/main.js

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "packages/meteor-accounts-cas"]
+	path = packages/meteor-accounts-cas
+	url = https://github.com/xaionaro/meteor-accounts-cas

+ 2 - 0
.meteor/packages

@@ -19,3 +19,5 @@ shell-server@0.2.4            # Server-side component of the `meteor shell` comm
 
 autopublish@1.0.7             # Publish all data to the clients (for prototyping)
 insecure@1.0.7                # Allow all DB writes from clients (for prototyping)
+random
+xaionaro:accounts-cas

+ 6 - 0
.meteor/versions

@@ -1,3 +1,4 @@
+accounts-base@1.3.1
 allow-deny@1.0.6
 autopublish@1.0.7
 autoupdate@1.3.12
@@ -16,6 +17,7 @@ check@1.2.5
 ddp@1.3.0
 ddp-client@2.0.0
 ddp-common@1.2.9
+ddp-rate-limiter@1.0.7
 ddp-server@2.0.0
 deps@1.0.12
 diff-sequence@1.0.7
@@ -37,6 +39,7 @@ insecure@1.0.7
 jquery@1.11.10
 launch-screen@1.1.1
 livedata@1.0.18
+localstorage@1.1.1
 logging@1.1.17
 meteor@1.7.0
 meteor-base@1.1.0
@@ -54,10 +57,12 @@ observe-sequence@1.0.16
 ordered-dict@1.0.9
 promise@0.8.9
 random@1.0.10
+rate-limit@1.0.8
 reactive-var@1.0.11
 reload@1.1.11
 retry@1.0.9
 routepolicy@1.0.12
+service-configuration@1.0.11
 shell-server@0.2.4
 spacebars@1.0.15
 spacebars-compiler@1.1.2
@@ -73,3 +78,4 @@ underscore@1.0.10
 url@1.1.0
 webapp@1.3.17
 webapp-hashing@1.0.9
+xaionaro:accounts-cas@0.0.7

+ 14 - 0
client/main.jsx

@@ -4,7 +4,21 @@ import { render } from 'react-dom';
  
 import { router } from '../imports/startup/client/Router.jsx';
 
+Meteor.settings = {
+	"public": {
+		"cas": {
+			"loginUrl": "https://login.mephi.ru/login",
+			"proxyUrl": "https://start.mephi.ru/",
+			"popup": false,
+		}
+	}
+}
+
 Meteor.startup(() => {
+	document.Meteor = Meteor;
+
+	Meteor.initCas();
+
 	render(router(), document.getElementById('render-target'));
 });
 

+ 58 - 4
imports/ui/Common.jsx

@@ -1,26 +1,80 @@
 import React, { Component } from 'react';
+import { Meteor } from 'meteor/meteor';
 
 import Services from './Services.jsx';
 
 export default class Common extends Component {
 
+	constructor(props) {
+		super(props);
+
+		this.state = {Services: new Services};
+
+		document.Common = this;
+	}
+
 	getServices() {
-		return Services.get();
+		return this.state.Services.get();
 	}
 
 	renderServices() {
-		return <Services/>;
+		return this.state.Services.render();
+	}
+
+	postAuthDeauth(err) {
+		if (err != null) {
+			console.log('postAuthDeauth() error: ', err);
+			return;
+		}
+
+		this.goToStartPage();
+		//this.forceUpdate();
+	}
+
+	auth() {
+		Meteor.loginWithCas({}, this.postAuthDeauth.bind(this));
+
+		return false;
+	}
+
+	logout() {
+		Meteor.logout(this.postAuthDeauth.bind(this));
+
+		return false;
+	}
+
+	renderAuthArea() {
+		if (!Meteor.loggingIn()) {
+			return <a href='#' onClick={function(e){e.preventDefault();document.Common.auth()}}>войти</a>
+		}
+		var user;
+		var interval = setInterval(function(){
+			user = Meteor.user();
+			if (user == null) {
+				return;
+			}
+			$('#fullName').text(user.profile['cas:full_name']);
+			clearInterval(interval);
+		}, 500);
+		var forceUpdate = this.forceUpdate;
+		return <div id='authed'><span id='fullName'>...</span> — <a href='#' onClick={this.logout.bind(this)}>выйти</a></div>
+	}
+
+	goToStartPage() {
+		$('select#services :nth-child(1)').prop('selected', true);
+		this.state.Services.onChange();
+		return false;
 	}
 
 	render() {
 		return <div id='Common'>
 			<header>
-				<a href='https://start.mephi.ru/start' target='iframe' onClick={function(){$('select#services :nth-child(1)').prop('selected', true); $('iframe').trigger('change');return false}}><img id='logo' src='/images/mephi_logo_onwhite_32px.png' alt='MEPHI logo' width='32px' height='32px'/></a>
+				<a href='https://start.mephi.ru/start' target='iframe' onClick={this.goToStartPage}><img id='logo' src='/images/mephi_logo_onwhite_32px.png' alt='MEPHI logo' width='32px' height='32px'/></a>
 				<nav>
 					{this.renderServices()}
 				</nav>
 				<div id='auth'>
-					test
+					{this.renderAuthArea()}
 				</div>
 			</header>
 			<iframe name='iframe' id='iframe' src='/start'></iframe>

+ 25 - 10
imports/ui/Services.jsx

@@ -2,21 +2,36 @@ import React, { Component } from 'react';
 
 import Service from './Service.jsx';
 
+
 export default class Services extends Component {
+
+	constructor(props) {
+		super(props);
+
+		this.state = {servicesList: [
+					{ link_to: 'https://start.mephi.ru/start', name: 'Стартовая страница' },
+					{ link_to: 'https://login.mephi.ru/login?service=https://voip.mephi.ru/login', name: 'IP-телефония' },
+					{ link_to: 'https://login.mephi.ru/login?service=https://cps.mephi.ru', name: 'Система учёта рабочего времени' },
+					{ link_to: 'https://login.mephi.ru/login?service=https://tasks.mephi.ru', name: 'Система «Задачи»' },
+					{ link_to: 'https://login.mephi.ru/login?service=https://chat.mephi.ru', name: 'Чат' },
+					{ link_to: 'https://login.mephi.ru/login?service=https://dc.mephi.ru', name: 'ЦОД' },
+					{ link_to: 'https://login.mephi.ru/login?service=https://cloud.campus.mephi.ru/apps/user_cas/login', name: 'Файловое облако' },
+				]};
+
+		document.Services = this;
+	}
+
 	get() {
-		return [
-			{ link_to: 'https://start.mephi.ru/start', name: 'Стартовая страница' },
-			{ link_to: 'https://login.mephi.ru/login?service=https://voip.mephi.ru/login', name: 'IP-телефония' },
-			{ link_to: 'https://login.mephi.ru/login?service=https://cps.mephi.ru', name: 'Система учёта рабочего времени' },
-			{ link_to: 'https://login.mephi.ru/login?service=https://tasks.mephi.ru', name: 'Система «Задачи»' },
-			{ link_to: 'https://login.mephi.ru/login?service=https://chat.mephi.ru', name: 'Чат' },
-			{ link_to: 'https://login.mephi.ru/login?service=https://dc.mephi.ru', name: 'ЦОД' },
-			{ link_to: 'https://login.mephi.ru/login?service=https://cloud.campus.mephi.ru/apps/user_cas/login', name: 'Файловое облако' },
-		];
+		return this.state.servicesList;
+	}
+
+	onChange() {
+		var link_to = $('select#services option:selected')[0].dataset.link;
+		$('iframe').attr('src', link_to);
 	}
 
 	render() {
-		return	<select id='services' onChange={function(ev){var link_to = ev.target.selectedOptions[0].dataset.link;$('iframe').attr('src', link_to)}}>
+		return	<select id='services' onChange={this.onChange}>
 				{this.get().map((service) => (
 					<Service key={service.link_to} service={service}/>
 				))}

+ 1 - 0
packages/meteor-accounts-cas

@@ -0,0 +1 @@
+Subproject commit 5c5150025dcda5c4eae726e20cc5b9efee8159be

+ 9 - 1
server/main.js

@@ -1,5 +1,13 @@
 import { Meteor } from 'meteor/meteor';
 
 Meteor.startup(() => {
-  // code to run on server at startup
+	Meteor.settings = {
+		"cas": {
+			"validateUrl": "https://login.mephi.ru/serviceValidate",
+			"proxyUrl": "https://start.mephi.ru/",
+			"autoClose": true,
+			"casVersion": 2.0,
+			"popup": false,
+		},
+	}
 });