Skip to content

Commit

Permalink
Cleanup / Sanity checks
Browse files Browse the repository at this point in the history
Signed-off-by: Walker Crouse <walkercrouse@hotmail.com>
  • Loading branch information
windy1 committed Feb 13, 2017
1 parent 061dd20 commit 7c3b1c1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
14 changes: 8 additions & 6 deletions app/ore/project/factory/ProjectFactory.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import scala.concurrent.duration.Duration
import scala.util.Try

/**
* Handles creation of Project's and their components.
* Manages the project and version creation pipeline.
*/
trait ProjectFactory {

Expand Down Expand Up @@ -62,10 +62,13 @@ trait ProjectFactory {
val pluginFileName = uploadData.pluginFileName
var signatureFileName = uploadData.signatureFileName

// file extension constraints
if (!pluginFileName.endsWith(".zip") && !pluginFileName.endsWith(".jar"))
throw InvalidPluginFileException("error.plugin.fileExtension")
if (!signatureFileName.endsWith(".sig") && !signatureFileName.endsWith(".asc"))
throw InvalidPluginFileException("error.plugin.sig.fileExtension")

// check user's public key validity
if (owner.pgpPubKey.isEmpty)
throw new IllegalArgumentException("error.plugin.noPubKey")
if (!owner.isPgpPubKeyReady)
Expand All @@ -74,19 +77,21 @@ trait ProjectFactory {
var pluginPath = uploadData.pluginFile.file.toPath
var sigPath = uploadData.signatureFile.file.toPath

// verify detached signature
if (!this.pgp.verifyDetachedSignature(pluginPath, sigPath, owner.pgpPubKey.get))
throw InvalidPluginFileException("error.plugin.sig.failed")

// move uploaded files to temporary directory while the project creation
// process continues
val tmpDir = this.env.tmp.resolve(owner.username)
if (notExists(tmpDir))
createDirectories(tmpDir)

val signatureFileExtension = signatureFileName.substring(signatureFileName.lastIndexOf("."))
signatureFileName = pluginFileName + signatureFileExtension

pluginPath = copy(pluginPath, tmpDir.resolve(pluginFileName), StandardCopyOption.REPLACE_EXISTING)
sigPath = copy(sigPath, tmpDir.resolve(signatureFileName), StandardCopyOption.REPLACE_EXISTING)

// create and load a new PluginFile instance for further processing
val plugin = new PluginFile(pluginPath, sigPath, owner)
plugin.loadMeta()
plugin
Expand All @@ -103,15 +108,12 @@ trait ProjectFactory {
// Make sure user has a key
if (user.pgpPubKey.isEmpty)
return Some("error.pgp.noPubKey")

// Make sure the user has waited long enough to use a key
if (!user.isPgpPubKeyReady)
return Some("error.pgp.keyChangeCooldown")
}

if (user.isLocked)
return Some("error.user.locked")

None
}

Expand Down
2 changes: 2 additions & 0 deletions app/ore/user/notification/NotificationTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import db.impl.OrePostgresDriver
import db.table.MappedType
import slick.jdbc.JdbcType

import scala.language.implicitConversions

/**
* Represents the different types of notifications.
*/
Expand Down
7 changes: 6 additions & 1 deletion app/security/spauth/SpongeAuthApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package security.spauth
import java.util.concurrent.TimeoutException
import javax.inject.Inject

import com.google.common.base.Preconditions._
import ore.OreConfig
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads._
Expand Down Expand Up @@ -40,7 +41,7 @@ trait SpongeAuthApi {
*
* @param username Username
* @param email Email
* @param password Password
* @param password Password (nullable)
* @param verified True if should bypass email verification
* @return Newly created user
*/
Expand All @@ -66,6 +67,8 @@ trait SpongeAuthApi {
password: String,
verified: Boolean = false,
dummy: Boolean = false): Either[String, SpongeUser] = {
checkNotNull(username, "null username", "")
checkNotNull(email, "null email", "")
var params = Map(
"api-key" -> Seq(this.apiKey),
"username" -> Seq(username),
Expand All @@ -84,6 +87,7 @@ trait SpongeAuthApi {
* @return User with username
*/
def getUser(username: String): Option[SpongeUser] = {
checkNotNull(username, "null username", "")
val url = route("/api/users/" + username) + s"?apiKey=$apiKey"
readUser(this.ws.url(url).get()).right.toOption
}
Expand All @@ -95,6 +99,7 @@ trait SpongeAuthApi {
* @return Deleted user
*/
def deleteUser(username: String): Either[String, SpongeUser] = {
checkNotNull(username, "null username", "")
val url = route("/api/users") + s"?username=$username&apiKey=$apiKey"
readUser(this.ws.url(url).delete())
}
Expand Down
7 changes: 7 additions & 0 deletions conf/evolutions/default/68.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# --- !Ups

alter table sign_ons rename to user_sign_ons;

# --- !Downs

alter table user_sign_ons rename to sign_ons;

0 comments on commit 7c3b1c1

Please sign in to comment.