<commit_before>'use strict'

var User = require('seneca-user')
var Auth = require('seneca-auth')
var AuthLocal = require('seneca-local-auth')
var AuthGoogle = require('seneca-google-auth')
var Concorda = require('./concorda')
var Lodash = require('lodash')

module.exports = function (server, options, next) {
  server.dependency('chairo')

  // Set up our seneca plugins
  var seneca = server.seneca

  seneca.use(User)
  seneca.use(Concorda)

  // Local auth should come built in and preconfigured
  seneca.use(Auth, {
    restrict: '/api',
    redirect:{
      login: {
        always: true,
        win:  '/',
        fail: '/login'
      }
    }
  })

  seneca.use(AuthGoogle, {
    provider: 'google',
    password: '',
    clientId: '',
    clientSecret: '',
    isSecure: false
  })

  // Should read from options too, should happen in Concorda
  var admin = {
    name: process.env.USER_NAME || 'Admin',
    email: process.env.USER_EMAIL || '<EMAIL>',
    password: <PASSWORD>.<PASSWORD> || '<PASSWORD>'
  }

  // Dummy data, to be removed
  Lodash.each([
    {name: admin.name, email: admin.email, password: admin.password},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'}
  ], (user) => {
    seneca.act({role: 'user', cmd: 'register'}, user)<commit_msg>add support for other apps to login using Google<commit_after>'use strict'

var User = require('seneca-user')
var Auth = require('seneca-auth')
var AuthLocal = require('seneca-local-auth')
var AuthGoogle = require('seneca-google-auth')
var Concorda = require('./concorda')
var Lodash = require('lodash')

module.exports = function (server, options, next) {
  server.dependency('chairo')

  // Set up our seneca plugins
  var seneca = server.seneca

  seneca.use(User)
  seneca.use(Concorda)

  // Local auth should come built in and preconfigured
  seneca.use(Auth, {
    restrict: '/api',
    redirect:{
      login: {
        always: true,
        win:  '/',
        fail: '/login'
      }
    }
  })

  seneca.use(AuthGoogle, {
    provider: 'google',
    password: '',
    clientId: '',
    clientSecret: '',
    isSecure: false
  })

  seneca.add('role: auth, cmd: loginGoogle', function (args, done){
    var callback_url = Lodash.get(args, 'req$.auth.credentials.query.callback_url')

    this.prior(args, function (err, data){
      if (callback_url) {
        data.http$ = data.http$ || {}
        data.http$.redirect = callback_url
      }
      done(err, data)
    })
  })


  // Should read from options too, should happen in Concorda
  var admin = {
    name: process.env.USER_NAME || 'Admin',
    email: process.env.USER_EMAIL || '<EMAIL>',
    password: process.env.USER_PASS || '<PASSWORD>'
  }

  // Dummy data, to be removed
  Lodash.each([
    {name: admin.name, email: admin.email, password: <PASSWORD>},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'},
    {name: '<NAME>', email: '<EMAIL>', password: '<PASSWORD>'}
  ], (user) => {
    seneca.act({role: 'user', cmd: 'register'}, user)
{'fraction_non_alphanumeric': 0.1785069235400361, 'fraction_numerical': 0.0, 'mean_word_length': 3.2657252888318355, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 36, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5728408', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1106, 'n_words': 278}