Пример #1
0
        public RODResponseMessage Post(handle login)
        {
            RODResponseMessage msg = new RODResponseMessage();

            if (login.publicKey.Length <= 4)
            {
                msg.result = 0;
                msg.message = "Unable to login. Please re-type your private key (case sensitive.)";
                return msg;
            }

            handle og = (from m in db.handles
                         where m.name == login.name.ToLower() && m.active == 1 && m.privateKey.StartsWith(login.publicKey)
                         select m).FirstOrDefault();

            if(og != null && Membership.ValidateUser(og.publicKey, og.privateKey)) {
                FormsAuthentication.SetAuthCookie(og.publicKey, true);
                msg.result = 1;
                msg.message = og.privateKey;
            } else {
                msg.result = 0;
                msg.message = "Unable to login. Please re-type your private key (case sensitive.)";
            }

            return msg;
        }
Пример #2
0
        // GET api/tagline
        // get current user tagline
        public handle Get()
        {
            handle tagline = new handle();
            tagline.id = -1;

            if (User.Identity.IsAuthenticated)
            {
                string user_id = User.Identity.Name;
                tagline = (from handle r in db.handles where r.userGuid.Equals(User.Identity.Name) select r).FirstOrDefault();
            }

            return tagline;
        }
        // POST api/values
        public RODResponseMessage Post(handle check_handle)
        {
            handle currently_exists = (from m in db.handles where m.name.Equals(check_handle.name) && m.active == 1 select m).FirstOrDefault();

            // always return handle name so the client knows which response
            // they are getting

            if (currently_exists == null)
            {
                return new RODResponseMessage { message = check_handle.name, result = 1 };
            }
            else
            {
                return new RODResponseMessage { message = check_handle.name, result = 0 };
            }
        }
Пример #4
0
        // POST api/values
        public handle Post(handle value)
        {
            handle error = new handle();
            error.active = -1;
            error.name = "There was an error.";

            if (value != null)
            {
                handle currently_exists = (from m in db.handles where m.name.Equals(value.name) && m.active == 1 select m).FirstOrDefault();

                if (currently_exists == null)
                {

                    handle safe_handle = new handle();
                    Guid public_key = Guid.NewGuid();
                    Guid private_key = Guid.NewGuid();

                    // Attempt to register the user
                    MembershipCreateStatus createStatus;
                    Membership.CreateUser(public_key.ToString(), private_key.ToString(), "anon", null, null, true, null, out createStatus);

                    if (createStatus == MembershipCreateStatus.Success)
                    {
                        FormsAuthentication.SetAuthCookie(public_key.ToString(), true /* createPersistentCookie */);
                        safe_handle.name = value.name;
                        safe_handle.userGuid = public_key.ToString();
                        safe_handle.active = 1;
                        // free handle yay

                        safe_handle.publicKey = public_key.ToString();
                        safe_handle.privateKey = private_key.ToString();

                        // send email about it

                        MailMessage Message = new MailMessage();
                        SmtpClient Smtp = new SmtpClient();

                        string password = System.Web.Configuration.WebConfigurationManager.AppSettings["MailPassword"];

                        System.Net.NetworkCredential SmtpUser = new System.Net.NetworkCredential("*****@*****.**", password);

                        string email = "new handle registered: \n\n";
                        email = safe_handle.name + "\n\n";

                        Message.From = new MailAddress("*****@*****.**");
                        Message.To.Add(new MailAddress("*****@*****.**"));
                        Message.IsBodyHtml = false;
                        Message.Subject = "new handle";
                        Message.Body = email;
                        Message.Priority = MailPriority.Normal;
                        Smtp.EnableSsl = false;

                        Smtp.Credentials = SmtpUser;
                        Smtp.Host = "198.57.199.92";
                        Smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                        Smtp.Port = 26;

                        Smtp.Send(Message);

                        db.handles.Add(safe_handle);
                        db.SaveChanges();
                        return safe_handle;
                    }
                    else
                    {
                        return error;
                    }

                }
                else
                {

                    handle taken = new handle();
                    taken.active = 0;
                    taken.name = value.name;
                    return taken;

                }

            }

            return error;
        }