Пример #1
0
        public async Task <object> Login([FromBody] LoginIn data)
        {
            var user = await context.Users.Where(x => x.Email == data.Email && x.Password == data.Password).FirstOrDefaultAsync();

            if (user == null)
            {
                HttpContext.Response.StatusCode = 401;
                return("login failed");
            }
            var session = AuthFilter.AddSession(user.Id, data.Deviceid, user.Email);
            await context.SaveChangesAsync();

            return(new LoginOut
            {
                Sessionid = session
            });
        }
Пример #2
0
        public async Task <object> CreateUser([FromBody] CreateUserIn user)
        {
            if (!ModelState.IsValid || user == null)
            {
                if (user == null)
                {
                    return(BadRequest("received no package,, recheck frontend"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }

            var u = new User
            {
                Id        = Guid.NewGuid(),
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Email     = user.Email,
                Password  = user.Password
            };

            context.Users.Add(u);
            await context.SaveChangesAsync();

            var sessionid = AuthFilter.AddSession(u.Id, user.Deviceid, user.Email);

            return(new CreateUserOut
            {
                Sessionid = sessionid,
                Firstname = u.FirstName,
                Lastname = u.LastName,
                Email = u.Email
            });
        }