コード例 #1
0
        public IHttpActionResult PostComment(Comment comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Get the username printed on the incoming token
            string username = User.Identity.Name;

            // Get the actual user from the database (may return null if not found!)
            ChirperUser user = db.Users.FirstOrDefault(u => u.UserName == username);

            if (user == null)
            {
                return(Unauthorized());
            }

            comment.UserId      = user.Id;
            comment.DateCreated = DateTime.Now;

            db.Comments.Add(comment);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = comment.CommentId }, comment));
        }
コード例 #2
0
        public async Task <IdentityResult> RegisterUser(RegistrationModel model)
        {
            var user = new ChirperUser
            {
                UserName = model.EmailAddress,
                Email    = model.EmailAddress
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            return(result);
        }
コード例 #3
0
        //Task for registering new user
        public async Task <IdentityResult> RegisterUser(RegistrationModel userModel)
        {
            //Instantiate new ChirperUser
            ChirperUser user = new ChirperUser
            {
                UserName = userModel.EmailAddress,
                Email    = userModel.EmailAddress
            };


            //Creates the user, stores the password in encrypted format
            var result = await _userManager.CreateAsync(user, userModel.Password);

            return(result);
        }
コード例 #4
0
        //verifies user exists in database with provided username and password
        public async Task <ChirperUser> FindUser(string userName, string password)
        {
            ChirperUser user = await _userManager.FindAsync(userName, password);

            return(user);
        }