示例#1
0
        public static bool check(string user, string pass, out string reason)
        {
            bool flag1 = false;

            reason = "user doesn't exist or invalid password";
            bool flag2 = UserDb.check(user, pass);

            if (flag2)
            {
                User user1 = UserDb.lookup(user);
                flag1 = user1.isadmin();
                switch (user1.info["status"])
                {
                case "pending":
                    reason = "Sorry you must activate using the token from your email first";
                    return(false);

                default:
                    string stuff = user1.info["cached"];
                    if (stuff != null && stuff.Length > 0)
                    {
                        clib.imsg("found cached life of {0}", (object)stuff);
                        if (clib.time() > clib.atoi(stuff))
                        {
                            clib.imsg("EXPIRED, MAKE HIM CHECK AGAIN age {0} {1}", (object)(clib.time() - clib.atoi(stuff)), (object)stuff);
                            flag2 = false;
                        }
                    }
                    break;
                }
            }
            if (!flag1 && !Vuser.valid_user(user, out reason))
            {
                return(false);
            }
            if (!flag2)
            {
                string dest = Ini.getstring(En.auth_imap);
                if (dest.Length > 0)
                {
                    Imap imap = new Imap();
                    clib.imsg("auth_imap {0} {1}", (object)user, (object)dest);
                    string result;
                    if (imap.login(dest, 143, "nossl", user, pass, out result))
                    {
                        NameValueCollection info = new NameValueCollection();
                        User user1 = UserDb.lookup(user);
                        if (user1 != null && user1.info != null)
                        {
                            info = user1.info;
                        }
                        info.Set("cached", clib.int_to_string(clib.time() + 604800));
                        clib.imsg("Imap: login worked for that user/pass {0}", (object)user);
                        string reason1;
                        if (!UserDb.add(user, pass, info, "", out reason1))
                        {
                            clib.imsg("cacheadd: {0}", (object)reason1);
                        }
                        imap.netclose();
                        flag2 = true;
                    }
                    else
                    {
                        clib.imsg("imap: login failed on remost host {0}", (object)result);
                    }
                }
            }
            return(flag2);
        }