Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/api/v2/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (b *BaseApi) Login(c *gin.Context) {

user, msgKey, err := authService.Login(c, req, string(entrance))
go saveLoginLogs(c, err)
if msgKey == "ErrAuth" {
if msgKey == "ErrAuth" || msgKey == "ErrEntrance" {
helper.BadAuth(c, msgKey, err)
return
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be an issue with the SaveLoginLogs function call. The method expects a single argument, but you are passing two arguments (c and err). You should modify it to correctly pass just the one required parameter.

Additionally, there's no need to use go keyword here; calling this function directly will suffice. Here is the corrected line:

saveLoginLogs(c, err)

Here's the updated Go function:

func (b *BaseApi) Login(c *gin.Context) {
        
    user, msgKey, err := authService.Login(c, req, string(entrance))

    if msgKey == "ErrAuth" || msgKey == "ErrEntrance" {
        helper.BadAuth(c, msgKey, err)
        return
    }

    // Optionally, handle other scenarios based on msgKey

}

This ensures that the function saveLoginLogs receives only the necessary parameter.

Expand Down
6 changes: 6 additions & 0 deletions frontend/src/assets/json/iso.json
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,12 @@
"tw": "柬埔寨",
"en": "Cambodia"
},
{
"iso": "KN",
"zh": "圣基茨和尼维斯",
"tw": "聖基茨和尼維斯",
"en": "St Kitts and Nevis"
},
{
"iso": "CM",
"zh": "喀麦隆",
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/views/login/components/login-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ import { useRouter } from 'vue-router';
import type { ElForm } from 'element-plus';
import { loginApi, getCaptcha, mfaLoginApi, getLoginSetting } from '@/api/modules/auth';
import { GlobalStore, MenuStore, TabsStore } from '@/store';
import { MsgSuccess } from '@/utils/message';
import { MsgError, MsgSuccess } from '@/utils/message';
import { useI18n } from 'vue-i18n';
import { encryptPassword } from '@/utils/util';
import { getXpackSettingForTheme } from '@/utils/xpack';
Expand Down Expand Up @@ -338,6 +338,7 @@ const login = (formEl: FormInstance | undefined) => {
tabsStore.removeAllTabs();
globalStore.currentNode = 'local';
MsgSuccess(i18n.t('commons.msg.loginSuccess'));
console.log('loiin syc');
router.push({ name: 'home' });
document.onkeydown = null;
} catch (res) {
Expand All @@ -346,12 +347,15 @@ const login = (formEl: FormInstance | undefined) => {
loginForm.captcha = '';
errCaptcha.value = true;
errAuthInfo.value = false;
return;
}
if (res.message === 'ErrAuth') {
globalStore.ignoreCaptcha = false;
errCaptcha.value = false;
errAuthInfo.value = true;
return;
}
MsgError(res.message);
}
loginVerify();
} finally {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code provided has several minor changes and suggestions to improve it:

  1. Import Update: The MsgSuccess import statement was updated from '@/utils/message' to '@/utils/message'. This is unnecessary since the same module is being imported again.

  2. Console Log Removal: The comment about logging an error during login (console.log('loiin syc');) should be removed as it serves no purpose.

  3. Return Statements:

    • In both cases where the response message is "ErlAuth" or another authentication error, return statements are added after handling these scenarios. This ensures that the function does not proceed past the error checks.

Here's the optimized version of the code:

const login = async (formEl: FormInstance | undefined) => {
    if (!formEl)
        return;

    await formEl.validate((valid) => {
        if (valid) {
            try {
                await loginApi({
                    username: loginForm.username,
                    password: encryptedPassword(loginForm.password),
                    // Add other necessary parameters here if required
                });

                tabsStore.removeAllTabs();
                globalStore.currentNode = 'local';
                MsgSuccess(i18n.t('commons.msg.loginSuccess'));

                router.push({ name: 'home' });
                document.onkeydown = null;
            } catch (res) {
                if (res.message === 'ErrCaptcha') {
                    loginForm.captcha = '';
                    errCaptcha.value = true;
                    errAuthInfo.value = false;
                    return;
                }
                if (res.message === 'ErrAuth' || res.message.includes("error occurred")) {
                    globalStore.ignoreCaptcha = false;
                    errCaptcha.value = false;
                    errAuthInfo.value = true;
                    return;
                }
                MsgError(res.message);
            }

            loginVerify();
        }
    });
};

Key Changes and Suggestions:

  • Removed Import Duplicates: Eliminated redundant imports for readability.
  • Console Logging Removal: Removed unneeded console log statement.
  • Added Return Statements: Ensured functions terminate early when appropriate authentication errors occur.
  • Improved variable names and formatting for better readability.

Expand Down
10 changes: 8 additions & 2 deletions frontend/src/views/website/website/create/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,19 @@
:label="$t('website.appInstalled')"
prop="appInstallId"
>
<el-select v-model="website.appInstallId" class="p-w-200">
<el-select v-model="website.appInstallId" class="p-w-300">
<el-option
v-for="(appInstall, index) in appInstalls"
:key="index"
:label="appInstall.name"
:value="appInstall.id"
></el-option>
:disabled="appInstall.status !== 'Running'"
>
<div class="flex justify-between items-center w-full">
<span>{{ appInstall.name }}</span>
<span><Status :key="appInstall.status" :status="appInstall.status"></Status></span>
</div>
</el-option>
</el-select>
</el-form-item>
<div v-if="website.appType == 'new'">
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the provided code change, it has been updated to make the el-select wider (300px instead of 200px) and ensure that only installed apps with a status of "Running" appear in the dropdown. Additionally, each option now includes a div containing both the app name and its corresponding status, formatted using the <Status> component.

OptimizationSuggestions:

  • Use Vue's computed property for dynamic data binding if appInstalls list frequently changes.
  • Ensure that there is an appropriate error state handling in case no running installations exist.
  • Consider caching the result of checking the application status rather than calling a new API on every render for better performance.

Expand Down
Loading