Ejemplo n.º 1
0
        public void CreateAccount(string username, string email, string password, string authId)
        {
            // Add gogs user
            using (var client = new WebClient())
            {
                var    obj  = new { source_id = _sourceId, username = username, email = email, login_name = email, password = password };
                string json = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
                client.Headers[HttpRequestHeader.ContentType] = "application/json";
                Uri    baseUri  = new Uri(_host);
                Uri    finalUri = new Uri(baseUri, "api/v1/admin/users?token=" + _accessToken);
                string result   = client.UploadString(finalUri, "POST", json);

                JObject resultJson = JObject.Parse(result);

                // Add an external auth for them
                MysqlDatabase mySQL   = new MysqlDatabase(_server, _database, _username, _password, _port);
                string        sql     = @"INSERT INTO gogs.external_login_user (external_id, user_id, login_source_id) VALUES ({0}, {1}, {2})";
                var           results = mySQL.Query(sql, new object[] { authId, resultJson["id"], _sourceId });
            }
        }
Ejemplo n.º 2
0
        public DateTime LastActive(string email)
        {
            // We need to check the actual git database
            MysqlDatabase mySQL   = new MysqlDatabase(_server, _database, _username, _password, _port);
            string        sql     = @"SELECT 
	                                CASE
		                                WHEN MAX(gogs.action.created) >= MAX(gogs.user.updated) THEN MAX(gogs.action.created)
		                                WHEN MAX(gogs.user.updated) >= MAX(gogs.action.created) THEN MAX(gogs.user.updated)
		                                ELSE MAX(gogs.user.updated)
	                                END AS LastUpdate
                                FROM gogs.user
                                LEFT JOIN gogs.action ON gogs.user.id = gogs.action.act_user_id
                                WHERE gogs.user.login_name = {0}";
            var           results = mySQL.Query(sql, new object[] { email });

            DateTime lastActive = new DateTime(1900, 1, 1);

            if (results != null && results.Any())
            {
                var result = results.First();
                DateTime.TryParse(result["LastUpdate"].ToString(), out lastActive);
            }
            return(lastActive);
        }