Exemplo n.º 1
0
        public ActionResult Register(User user)
        {
            if (string.IsNullOrEmpty(user.Login) || string.IsNullOrEmpty(user.Email))
            {
                if (string.IsNullOrEmpty(user.Login))
                {
                    ModelState.AddModelError("Login", "You must pick a username");
                }
                if (string.IsNullOrEmpty(user.Email))
                {
                    ModelState.AddModelError("Email", "You must provide an email address");
                }

                return(View("Registration", user));
            }

            if (CurrentServiceModel.IsUserNameAvailable(user.Login))
            {
                CurrentServiceModel.CreateUser(user);

                FormsAuthentication.SetAuthCookie(user.Login, true);

                return(RedirectToAction("Index", "Home"));
            }

            ModelState.AddModelError("Name", "This username is not available, please choose another");

            return(View("Registration", user));
        }
Exemplo n.º 2
0
        public ActionResult EditApplication(int id)
        {
            CurrentUserModel.CheckIsSiteAdmin();
            Application app = CurrentServiceModel.GetApplication(id);

            return(View("EditApplication", app));
        }
Exemplo n.º 3
0
        public ActionResult SaveSettings(Settings s)
        {
            if (!Settings.Default.InitialConfiguration)
            {
                CurrentUserModel.CheckIsSiteAdmin();
            }

            Settings.Default.DataPath      = s.DataPath;
            Settings.Default.OperationMode = s.OperationMode;
            Settings.Default.WebSiteHost   = s.WebSiteHost;
            Settings.Default.SmtpHost      = s.SmtpHost;
            Settings.Default.SmtpPassword  = s.SmtpPassword;
            Settings.Default.SmtpPort      = s.SmtpPort;
            Settings.Default.SmtpUser      = s.SmtpUser;
            Settings.Default.SmtpUseSSL    = s.SmtpUseSSL;

            CurrentUserModel.UpdateSettings(Settings.Default);

            Cydin.MvcApplication.UpdateRoutes();
            if (!CurrentServiceModel.ThereIsAdministrator())
            {
                return(Redirect(ControllerHelper.GetActionUrl("home", "Login", "User")));
            }
            else
            {
                CurrentServiceModel.EndInitialConfiguration();
                return(Redirect(ControllerHelper.GetActionUrl("home", null, null)));
            }
        }
Exemplo n.º 4
0
        ActionResult AuthorizeUser(string claimedUserId, string ticket, string returnUrl, string userEmail = null, string userName = null)
        {
            bool updating = !string.IsNullOrEmpty(ticket);

            User user = CurrentServiceModel.GetUserFromOpenId(claimedUserId);

            if (updating)
            {
                if (user == null)
                {
                    ViewData["Message"] = "User not registered";
                    return(View("Login"));
                }
                string newId = GetTicketId(ticket);
                CurrentServiceModel.UpdateOpenId(claimedUserId, newId);
                FormsAuthentication.SignOut();
            }

            // Try to migrate users using old Google OpenID to OAuth2
            if (user == null && !string.IsNullOrEmpty(userEmail))
            {
                var currentUser = CurrentServiceModel.GetUserByEmail(userEmail);
                if (currentUser != null && currentUser.OpenId.StartsWith("https://www.google.com/accounts/o8/id"))
                {
                    CurrentServiceModel.UpdateOpenId(currentUser.OpenId, claimedUserId);
                    user = currentUser;
                }
            }

            // This is a new user, send them to a registration page
            if (user == null)
            {
                ViewData["openid"] = claimedUserId;
                if (Settings.Default.SupportsMultiApps)
                {
                    return(Redirect(string.Format("~/home/User/register?openid={0}&name={1}&email={2}", Url.Encode(claimedUserId), Url.Encode(userName), Url.Encode(userEmail))));
                }
                else
                {
                    return(Redirect(string.Format("~/User/register?openid={0}&name={1}&email={2}", Url.Encode(claimedUserId), Url.Encode(userName), Url.Encode(userEmail))));
                }
            }

            FormsAuthentication.SetAuthCookie(user.Login, false);

            if (!string.IsNullOrEmpty(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else if (updating)
            {
                return(Redirect(ControllerHelper.GetActionUrl("home", "Index", "Home")));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
Exemplo n.º 5
0
        public ActionResult AddUser(string login, string password, string email)
        {
            CurrentUserModel.CheckIsSiteAdmin();

            User u = new User();

            u.Email = email;
            u.Login = login;
            u.Name  = login;
            u.SetPassword(password);

            CurrentServiceModel.CreateUser(u);
            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        public ActionResult AddOwnerAsync(int id, string email)
        {
            CurrentUserModel.ValidateProject(id);
            User u = CurrentServiceModel.GetUserByEmail(email);

            if (u != null)
            {
                CurrentUserModel.AddProjectOwner(id, u.Id);
                return(Content("OK"));
            }
            else
            {
                return(Content(""));
            }
        }
Exemplo n.º 7
0
        public ActionResult AddAdminAsync(string email)
        {
            CurrentUserModel.CheckIsAdmin();
            User u = CurrentServiceModel.GetUserByEmail(email);

            if (u != null)
            {
                CurrentUserModel.SetUserApplicationPermission(u.Id, ApplicationPermission.Administer, true);
                return(Content("OK"));
            }
            else
            {
                return(Content(""));
            }
        }
Exemplo n.º 8
0
 public ActionResult Setup()
 {
     if (Settings.Default.OperationMode != OperationMode.NotSet)
     {
         if (!CurrentServiceModel.ThereIsAdministrator())
         {
             return(Redirect(ControllerHelper.GetActionUrl("home", "Login", "User")));
         }
         else
         {
             RedirectToAction("Index", "Home");
         }
     }
     return(View());
 }
Exemplo n.º 9
0
        public ActionResult Update(string content)
        {
            try
            {
                UserModel m = CurrentUserModel;
                m.CheckIsAdmin();
                Application app = CurrentServiceModel.GetApplication(m.CurrentApplication.Id);
                app.Description = content;
                CurrentServiceModel.UpdateApplication(app);
                Cydin.Views.ViewHelper.ClearCache();

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString()));
            }
        }
Exemplo n.º 10
0
        public ActionResult UpdateApplication(Application app)
        {
            UserModel m = CurrentUserModel;

            m.CheckIsSiteAdmin();
            if (app.Id != -1)
            {
                Application capp = CurrentServiceModel.GetApplication(app.Id);
                capp.Name      = app.Name;
                capp.Subdomain = app.Subdomain;
                capp.Platforms = app.Platforms;
                CurrentServiceModel.UpdateApplication(capp);
            }
            else
            {
                app.Description = "<p>This is the home page of the add-in repository for " + app.Name + "</p><p>Click on the 'Edit Page' link to change the content of this welcome page</p>";
                CurrentServiceModel.CreateApplication(app);
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 11
0
        public ActionResult AppReleasePackage(int id)
        {
            AppRelease release = CurrentServiceModel.GetAppRelease(id);

            return(File(release.ZipPath, "application/zip", Path.GetFileName(release.ZipPath)));
        }
Exemplo n.º 12
0
        public ActionResult Authenticate(string returnUrl, string ticket)
        {
            var    r         = HttpContext.Request;
            bool   updating  = !string.IsNullOrEmpty(ticket);
            string loginView = "Login";
            var    response  = openid.GetResponse();

            if (response == null)
            {
                // Stage 2: user submitting Identifier
                Identifier id;
                if (Identifier.TryParse(Request.Form["openid_identifier"], out id))
                {
                    try
                    {
                        string host = updating ? Settings.Default.PreviousWebSiteHost : Settings.Default.WebSiteHost;
                        Realm  realm;
                        if (host.All(c => char.IsDigit(c) || c == '.' || c == ':'))
                        {
                            realm = new Realm("http://" + host);
                        }
                        else
                        {
                            realm = new Realm("http://*." + host);
                        }

                        IAuthenticationRequest req = openid.CreateRequest(Request.Form["openid_identifier"]);
//						IAuthenticationRequest req = openid.CreateRequest (Request.Form["openid_identifier"], realm);
                        OutgoingWebResponse res = req.RedirectingResponse;
                        return(new InternalOutgoingWebResponseActionResult(res));
                    }
                    catch (ProtocolException ex) {
                        ViewData["Message"] = ex.Message;
                        return(View(loginView));
                    }
                }
                else
                {
                    ViewData["Message"] = "Invalid identifier";
                    return(View(loginView));
                }
            }
            else
            {
                // Stage 3: OpenID Provider sending assertion response
                switch (response.Status)
                {
                case AuthenticationStatus.Authenticated:

                    User user = CurrentServiceModel.GetUserFromOpenId(response.ClaimedIdentifier);
                    if (updating)
                    {
                        if (user == null)
                        {
                            ViewData["Message"] = "User not registered";
                            return(View(loginView));
                        }
                        string newId = GetTicketId(ticket);
                        CurrentServiceModel.UpdateOpenId(response.ClaimedIdentifier, newId);
                        FormsAuthentication.SignOut();
                    }

                    // This is a new user, send them to a registration page
                    if (user == null)
                    {
                        ViewData["openid"] = response.ClaimedIdentifier;
                        if (Settings.Default.SupportsMultiApps)
                        {
                            return(Redirect(string.Format("~/home/User/register?openid={0}", Url.Encode(response.ClaimedIdentifier))));
                        }
                        else
                        {
                            return(Redirect(string.Format("~/User/register?openid={0}", Url.Encode(response.ClaimedIdentifier))));
                        }
                    }

                    Session["FriendlyIdentifier"] = response.FriendlyIdentifierForDisplay;
                    FormsAuthentication.SetAuthCookie(user.Login, false);

                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else if (updating)
                    {
                        return(Redirect(ControllerHelper.GetActionUrl("home", "Index", "Home")));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                case AuthenticationStatus.Canceled:
                    ViewData["Message"] = "Canceled at provider";
                    return(View(loginView));

                case AuthenticationStatus.Failed:
                    ViewData["Message"] = response.Exception.Message;
                    return(View(loginView));
                }
            }
            return(new EmptyResult());
        }