Beispiel #1
0
        public string UploadFileAPI(HttpPostedFile FileToUpload, string FolderID)
        {
            string AbsoluteUri;

            // Check HttpPostedFileBase is null or not
            if (FileToUpload == null || FileToUpload.ContentLength == 0)
            {
                return(null);
            }
            try
            {
                CloudBlockBlob blockBlob;
                Backbone       backbone = new Backbone();
                if (string.IsNullOrWhiteSpace(FolderID))
                {
                    // Create a block blob
                    blockBlob = blobContainer.GetBlockBlobReference(string.Format("{0}{1}", backbone.Random(7), Path.GetExtension(FileToUpload.FileName)));
                }
                else
                {
                    blockBlob = blobContainer.GetBlockBlobReference(string.Format("{0}/{1}{2}", FolderID, backbone.Random(7), Path.GetExtension(FileToUpload.FileName)));
                }

                // Set the object's content type
                blockBlob.Properties.ContentType = FileToUpload.ContentType;
                var data = FileToUpload.InputStream.Length;

                // upload to blob
                blockBlob.UploadFromStream(FileToUpload.InputStream);

                // get file uri
                AbsoluteUri = blockBlob.Name;
            }
            catch (Exception ExceptionObj)
            {
                throw ExceptionObj;
            }
            return(AbsoluteUri);
        }
Beispiel #2
0
        public static bool SignIn(HttpContextBase context, string email, string password, bool rememberMe, out string error)
        {
            error = null;
            photogEntities db = new photogEntities();

            try
            {
                var passwordHash = Backbone.ComputeSha256Hash(password).ToLower();
                var user         = db.Users.FirstOrDefault(x => x.email.ToLower() == email.ToLower() && x.password.ToLower() == passwordHash);

                if (user != null && !user.isVerified)
                {
                    error = "Account has not been verified. Please check your email for verification";
                }

                else if (user != null)
                {
                    var identity    = Identity(user);
                    var ctx         = context.Request.GetOwinContext();
                    var authManager = ctx.Authentication;

                    authManager.SignIn(identity);

                    return(true);
                }
                else
                {
                    error = "Invalid Username or Password";
                }
            }
            catch
            {
                error = "Server Error";
            }
            return(false);
        }