Skip to content
Snippets Groups Projects
Select Git revision
  • v2.3.1
  • master default
  • sp/trace-zero-ranges
  • stable-2.5
  • stable-2.4
  • stable-2.3
  • stable-2.2
  • stable-2.1
  • stable-2.0
  • stable-1.7
  • stable-1.6
  • stable-1.5
  • stable-1.4
  • stable-1.3
  • stable-1.2
  • stable-1.1
  • stable-1.0
  • stable-0.15
  • stable-0.14
  • stable-0.13
  • stable-0.12
  • v2.7.0-rc1
  • v2.7.0-rc0
  • v2.6.0
  • v2.5.1.1
  • v2.6.0-rc5
  • v2.6.0-rc4
  • v2.6.0-rc3
  • v2.6.0-rc2
  • v2.6.0-rc1
  • v2.6.0-rc0
  • v2.5.1
  • v2.5.0
  • v2.5.0-rc4
  • v2.5.0-rc3
  • v2.5.0-rc2
  • v2.5.0-rc1
  • v2.5.0-rc0
  • v2.4.1
  • v2.4.0.1
40 results

dma-helpers.c

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AccountController.cs 2.04 KiB
    
    using Coscine.STS.Models;
    using Microsoft.AspNetCore.Mvc;
    using System.IdentityModel.Claims;
    using System.Web.Security;
    using System.IdentityModel;
    using System.IdentityModel.Configuration;
    using System.IdentityModel.Protocols.WSTrust;
    using System.IdentityModel.Tokens;
    using System.Linq;
    using System.Security.Claims;
    using Microsoft.AspNetCore.Authentication.Cookies;
    using Microsoft.AspNetCore.Authentication;
    using System.Threading.Tasks;
    using System;
    using Coscine.STS.Utils;
    using System.Net;
    
    namespace Coscine.STS.Controllers
    {
        public class AccountController : Controller
        {
            [Route("[controller]/login")]
            public ActionResult Login(string returnUrl)
            {
                ViewBag.ReturnUrl = UrlGenerator.ExtendReturnUrl(returnUrl, Request);
                ViewBag.ORCiDUrl = ORCiDHandler.GetORCiDOAuthUrl() + UrlGenerator.ORCiDRedirectUrl();
                System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                ViewBag.AppJs = enc.GetString(Program.Configuration.GetAndWait("coscine/apps/login/appjs"));
                return View();
            }
    
            [HttpPost("[controller]/login")]
            public async Task<ActionResult> Login(LoginModel model, string returnUrl)
            {
                if (ModelState.IsValid)
                {
                    var claims = new[] { new System.Security.Claims.Claim(System.IdentityModel.Claims.ClaimTypes.Name, model.UserId.ToString()) };
    
                    var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
    
                    await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(identity));
                    
                    return Redirect(UrlGenerator.ExtendReturnUrl(returnUrl, Request));
                }
    
                ViewBag.ReturnUrl = UrlGenerator.ExtendReturnUrl(returnUrl, Request);
                ViewBag.ORCiDUrl = ORCiDHandler.GetORCiDOAuthUrl() + UrlGenerator.ORCiDRedirectUrl();
                ModelState.AddModelError("", "The userid provided is incorrect.");
                return View(model);
            }
        }
    }