username

Django: How to get current user in admin forms

杀马特。学长 韩版系。学妹 提交于 2019-11-27 03:33:44
In Django's ModelAdmin I need to display forms customized according to the permissions an user has. Is there a way of getting the current user object into the form class, so that i can customize the form in its __init__ method? I think saving the current request in a thread local would be a possibility but this would be my last resort think I'm thinking it is a bad design approach.... Here is what i did recently for a Blog: class BlogPostAdmin(admin.ModelAdmin): form = BlogPostForm def get_form(self, request, **kwargs): form = super(BlogPostAdmin, self).get_form(request, **kwargs) form.current

How to get Windows username in Java?

两盒软妹~` 提交于 2019-11-27 01:26:12
So what I am trying to do is let my Java find the user's name that windows is logged in with, so when I would say such a method, it would return the users name, like I use it in the User called Noah, java would return "Noah" and if I were on the user Amanda, Java would return "Amanda". How would I do this? Lookup the system property "user.name". String username = System.getProperty("user.name"); System Properties System.getProperty Demonstration: Main.java public class Main { public static void main(String[] args) { System.out.println(System.getProperty("user.name")); } } Output: c:\dev\src

How to get the username in C/C++ in Linux?

て烟熏妆下的殇ゞ 提交于 2019-11-27 01:20:17
问题 How can I get the actual "username" without using the environment (getenv, ...) in a program? 回答1: The function getlogin_r() defined in unistd.h returns the username. See man getlogin_r for more information. Its signature is: int getlogin_r(char *buf, size_t bufsize); Needless to say, this function can just as easily be called in C or C++. 回答2: From http://www.unix.com/programming/21041-getting-username-c-program-unix.html : /* whoami.c */ #define _PROGRAM_NAME "whoami" #include <stdlib.h>

How can I get the google username on Android?

我们两清 提交于 2019-11-26 18:45:28
I've seen references to using the AccountManager like Accessing Google Account Id /username via Android but it seems like it's for grabbing the authtoken? I just need access to the username, no passwords or any auth tokens. I'm using android 2.1 sdk. tommy chheng As mentioned in the comments, Roman's answer to How to get the Android device's primary e-mail address solves it. Here's the code i used that will also strip out the username from the email. public String getUsername() { AccountManager manager = AccountManager.get(this); Account[] accounts = manager.getAccountsByType("com.google");

How do I sign out in the Git Bash console in Windows?

亡梦爱人 提交于 2019-11-26 17:43:34
I'm using Git, on Windows, version 2.9.2.windows.1. I work on a repository project and when I do a push, it asked me to enter my GitHub username and password. I entered both my GitHub username and password to update the project. In my next push, it doesn't ask for my username and password any more. All my modifications for the project are updated. It looks like my username and password are "saved". How do I "unsave" them? How do I sign out? I tried git config --global --unset user.name git config --global --unset user.email git config --global --unset credential.helper But they do not make me

Get login username in java

天大地大妈咪最大 提交于 2019-11-26 17:23:09
How can I get the username/login name in Java? This is the code I have tried... try{ LoginContext lc = new LoginContext(appName,new TextCallbackHandler()); lc.login(); Subject subject = lc.getSubject(); Principal principals[] = (Principal[])subject.getPrincipals().toArray(new Principal[0]); for (int i=0; i<principals.length; i++) { if (principals[i] instanceof NTUserPrincipal || principals[i] instanceof UnixPrincipal) { String loggedInUserName = principals[i].getName(); } } } catch(SecurityException se){ System.out.println("SecurityException: " + se.getMessage()); } I get a SecurityException

Django: How to get current user in admin forms

被刻印的时光 ゝ 提交于 2019-11-26 10:32:56
问题 In Django\'s ModelAdmin I need to display forms customized according to the permissions an user has. Is there a way of getting the current user object into the form class, so that i can customize the form in its __init__ method? I think saving the current request in a thread local would be a possibility but this would be my last resort think I\'m thinking it is a bad design approach.... 回答1: Here is what i did recently for a Blog: class BlogPostAdmin(admin.ModelAdmin): form = BlogPostForm def

Get Windows username in a legacy (not WebExtensions) Firefox add-on

强颜欢笑 提交于 2019-11-26 09:46:08
问题 I am working a Firefox add-on (which is written in JavaScript) and need to determine the Windows user currently logged on. Is there a way to do this? 回答1: This does the trick on Windows: function getUser() { return Components.classes["@mozilla.org/process/environment;1"].getService(Components.interfaces.nsIEnvironment).get('USERNAME'); } 回答2: You can use nsIEnvironment interface to get USERNAME environmnet variable. 回答3: Following code works for me instead of onload event with function

C++ - GetUserName() when process is run as administrator

余生颓废 提交于 2019-11-26 08:35:48
问题 I have a simple C++ program that prompt the user name #include <windows.h> #include <Lmcons.h> #include <winbase.h> int _tmain(int argc, _TCHAR* argv[]) { wchar_t username[UNLEN + 1]; DWORD username_len = UNLEN + 1; ::GetUserName(username, &username_len); MessageBox(NULL, username, NULL, 1); return 1; } GetUserName() performs as expected in administrator accounts, meaning print the real user name. However, when run as administrator in a non-administrator account , I get the administrator name

How can I get the google username on Android?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 06:34:12
问题 I\'ve seen references to using the AccountManager like Accessing Google Account Id /username via Android but it seems like it\'s for grabbing the authtoken? I just need access to the username, no passwords or any auth tokens. I\'m using android 2.1 sdk. 回答1: As mentioned in the comments, Roman's answer to How to get the Android device's primary e-mail address solves it. Here's the code i used that will also strip out the username from the email. public String getUsername() { AccountManager