               document.location.href = "/classroom"
             else
               document.location.href = "/profile"
+
+  onTeamRegistration: (e) ->
+    e.preventDefault()
+    apiCall "POST", "/api/team/create", {team_name: @state.team_name, team_password: @state.team_password}
+    .done (resp) ->
+      switch resp.status
+        when 0
+            apiNotify resp
+        when 1
+            document.location.href = "/profile"
+
+  onTeamJoin: (e) ->
+    e.preventDefault()
+    e.preventDefault()
+    apiCall "POST", "/api/team/join", {team_name: @state.team_name, team_password: @state.team_password}
+    .done (resp) ->
+      switch resp.status
+        when 0
+            apiNotify resp
+        when 1
+            document.location.href = "/profile"
 
   setPage: (page) ->
     @setState update @state,

        </form>
      </Panel>

AuthPanel = React.createClass
  mixins: [React.addons.LinkedStateMixin]
  getInitialState: ->
    page: "Login"

  onRegistration: (e) ->
    e.preventDefault()
    console.log @state
    apiCall "POST", "/api/user/create_simple", @state
    .done (resp) ->
      switch resp.status
        when 0
          apiNotify resp
        when 1
          document.location.href = "/profile"

  onPasswordReset: (e) ->
    e.preventDefault()

    lastname: @linkState "lastname"
    firstname: @linkState "firstname"
    email: @linkState "email"
    teamName: @linkState "team_name"
    teamPassword: @linkState "team_password"

    if @state.page == "Team Management"
      <div>
        <Col md={6} mdOffset={3}>
          <TeamManagementForm onTeamJoin={@onTeamJoin} onTeamRegistration={@onTeamRegistration} {...links}/>
        </Col>
      </div>
    else
      <div>
        <Col md={6} mdOffset={3}>
          <LoginForm setPage={@setPage} status={@state.page} onRegistration={@onRegistration}
            onLogin={@onLogin} onPasswordReset={@onPasswordReset} {...links}/>
        </Col>
      </div>

$ ->
  React.render <AuthPanel/>, document.getElementById("auth-box")
