MCPcopy
hub / github.com/dgraph-io/dgraph / ResetPassword

Method ResetPassword

edgraph/multi_tenancy.go:31–81  ·  view source on GitHub ↗
(ctx context.Context, inp *ResetPasswordInput)

Source from the content-addressed store, hash-verified

29}
30
31func (s *Server) ResetPassword(ctx context.Context, inp *ResetPasswordInput) error {
32 query := fmt.Sprintf(`{
33 x as updateUser(func: eq(dgraph.xid, "%s")) @filter(type(dgraph.type.User)) {
34 uid
35 }
36 }`, inp.UserID)
37
38 userNQuads := []*api.NQuad{
39 {
40 Subject: "uid(x)",
41 Predicate: "dgraph.password",
42 ObjectValue: &api.Value{Val: &api.Value_StrVal{StrVal: inp.Password}},
43 },
44 }
45 req := &Request{
46 req: &api.Request{
47 CommitNow: true,
48 Query: query,
49 Mutations: []*api.Mutation{
50 {
51 Set: userNQuads,
52 Cond: "@if(gt(len(x), 0))",
53 },
54 },
55 },
56 doAuth: NoAuthorize,
57 }
58 ctx = x.AttachNamespace(ctx, inp.Namespace)
59 resp, err := (&Server{}).doQuery(ctx, req)
60 if err != nil {
61 return errors.Wrapf(err, "Reset password for user %s in namespace %d, got error:",
62 inp.UserID, inp.Namespace)
63 }
64
65 type userNode struct {
66 Uid string `json:"uid"`
67 }
68
69 type userQryResp struct {
70 User []userNode `json:"updateUser"`
71 }
72 var userResp userQryResp
73 if err := json.Unmarshal(resp.GetJson(), &userResp); err != nil {
74 return errors.Wrap(err, "Reset password failed with error")
75 }
76
77 if len(userResp.User) == 0 {
78 return errors.New("Failed to reset password, user doesn't exist")
79 }
80 return nil
81}
82
83// CreateNamespaceInternal creates a new namespace. Only superadmin is authorized to do so.
84// Authorization is handled by middlewares.

Callers 2

TestResetPasswordMethod · 0.45
resolveResetPasswordFunction · 0.45

Calls 2

AttachNamespaceFunction · 0.92
doQueryMethod · 0.80

Tested by 1

TestResetPasswordMethod · 0.36