|
41 | 41 | break; |
42 | 42 | } |
43 | 43 | $keys = array_map("trim", $keys); |
44 | | - try { |
45 | | - if (count($keys) == 1) { |
46 | | - $keyWasAdded = $USER->addSSHKey($keys[0], $OPERATOR); |
47 | | - if ($keyWasAdded) { |
48 | | - UnityHTTPD::messageSuccess("SSH Key Added", ""); |
49 | | - UnityHTTPD::redirect(); |
50 | | - } else { |
51 | | - UnityHTTPD::messageWarning("SSH Key Not Added", "This key already exists"); |
52 | | - UnityHTTPD::redirect(); |
53 | | - } |
| 44 | + foreach ($keys as $key) { |
| 45 | + try { |
| 46 | + $keyWasAdded = $USER->addSSHKey($key, $OPERATOR); |
| 47 | + } catch (NoKeyLoadedException) { |
| 48 | + UnityHTTPD::messageError("SSH Key Not Added", "This key is invalid"); |
| 49 | + UnityHTTPD::redirect(); |
| 50 | + } |
| 51 | + if ($keyWasAdded) { |
| 52 | + UnityHTTPD::messageSuccess("SSH Key Added", ""); |
| 53 | + UnityHTTPD::redirect(); |
54 | 54 | } else { |
55 | | - $numKeysAdded = $USER->addSSHKeys($keys, $OPERATOR); |
56 | | - $numKeysNotAdded = count($keys) - $numKeysAdded; |
57 | | - if ($numKeysAdded == 0) { |
58 | | - UnityHTTPD::messageWarning( |
59 | | - "SSH Keys Not Added", |
60 | | - "These keys already exist" |
61 | | - ); |
62 | | - UnityHTTPD::redirect(); |
63 | | - } elseif ($numKeysAdded == count($keys)) { |
64 | | - UnityHTTPD::messageSuccess("SSH Keys Added", ""); |
65 | | - UnityHTTPD::redirect(); |
66 | | - } else { |
67 | | - UnityHTTPD::messageWarning( |
68 | | - "Some SSH Keys Not Added", |
69 | | - // pluralization may be wrong here but I don't care |
70 | | - sprintf( |
71 | | - "%s keys were added. The other %s keys already existed.", |
72 | | - $numKeysAdded, |
73 | | - $numKeysNotAdded |
74 | | - ) |
75 | | - ); |
76 | | - UnityHTTPD::redirect(); |
77 | | - } |
| 55 | + UnityHTTPD::messageInfo("SSH Key Not Added", "This key already exists"); |
| 56 | + UnityHTTPD::redirect(); |
78 | 57 | } |
79 | | - } catch (NoKeyLoadedException $e) { |
80 | | - UnityHTTPD::messageError("Invalid SSH Key", ""); |
81 | | - UnityHTTPD::redirect(); |
82 | 58 | } |
83 | 59 | break; |
84 | 60 | case "delKey": |
|
0 commit comments